Link to home
Start Free TrialLog in
Avatar of Galina Besselyanova
Galina Besselyanova

asked on

Insert image from SQL database into email using CFMAIL

Hello experts!
Please help.
I  need to send an automatic email from the cf page and this email is populated from database.
Seems easy, however i have trouble to insert image into the  body of the email because it is stored as image type in the SQL 2005 database.
Here is a code.
<cfquery name=qName datasource=#dsn#>
SELECT     EMAIL_id,  SUBJECT, BODY, TO_WHOM, CC_WHOM, BCC_WHOM,  IS_FROM
FROM         EMAILCUSTOM
WHERE  EMAIL_ID=#url.bid#
</cfquery>
<cfmail
subject="#qName.subject#"
 from="#qName.is_from#"
 to="#qName.to_whom#"  >

<!---here is an image #qName.body#--->

This is an automatic message. Thank you.
</cfmail>
How  can i put an image into email and not on the page? (i tried <cfcontent type="image/gif" variable="#qName.body#"> and image displayed on the page)

thank you


Avatar of SidFishes
SidFishes
Flag of Canada image

Avatar of Galina Besselyanova
Galina Besselyanova

ASKER

What is a path for my image if it stored in db?
hmm .. I never store images in a db, (only links to images)  and my first thought was you could write it out to a temp file

however I found this http://www.forta.com/blog/index.cfm?mode=entry&entry=A61BC976-3048-80A9-EF7AE4D7D8F602B9

which makes it easier...and should eliminate the need for cfcontent

just create a getImage.cfm using whatever query structure you need and then

add

<img src="/getImage.cfm?imageid=123">

 to your mail body

not tested (no images in a db ;) but should work

thanks
So there is no way i can do this on one page?
If you're running 8.01+, try using the "content" attribute. You should be able to use it for both attachments and inline images.  

This entry is about pdf's, but the same concept should apply to any type of attachment/inline file
http://www.coldfusionjedi.com/index.cfm/2009/1/22/Ask-a-Jedi-Sending-a-dynamic-PDF-via-email


<cfmail ...>
     <cfmailparam file="someGIFImage.GIF"
         contentID="someUniqueStringIdentifyingImage1"
         content="#qName.body#"
         type="inline">

     <img src="cid:someUniqueStringIdentifyingImage1" />
      This is an automatic message. Thank you.
</cfmail>
Correction: That should be disposition, not type.  

<!--- must use type="HTML" for inline images --->
<cfmail type="html" ....>
     <cfmailparam file="someGIFImage.GIF"
         contentID="someUniqueStringIdentifyingImage1"
         content="#qName.body#"
         disposition="inline" >

     <img src="cid:someUniqueStringIdentifyingImage1" />
      This is an automatic message. Thank you.
</cfmail>
sorry,
but i don't have physical file. I have image type data in the table in SQL database.
 So, what is a someGIFImage.gif in your code?
ASKER CERTIFIED SOLUTION
Avatar of _agx_
_agx_
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial