Sending Embedded Images in E-Mails

ColdFusion Add comments

If you need to put some images into your e-mails the common way is referring them via their full path on the internet. This is a basic and easy way but most of the e-mail clients do not allow to show these kind of images in the mail as default.

Instead of referring an online image, you can also embed them into your e-mail via following method in ColdFusion.

<!--- Generating a random/unique ID for our image --->
<cfset imageID = GetTickCount()>

<cfset request.sender = "Oğuz Demirkapı <blog@mydomain.net>">
<cfset request.receiver = "Oğuz Demirkapı <blog@mydomain.net>">

<cfset currentDir = GetDirectoryFromPath(ExpandPath("*.*"))>
<cfset imageFile = currentDir & "odfoto.jpg">

<cfmail
    to="#request.receiver#"
    from="#request.sender#"
    subject="Test: Sending Embedded Images in E-Mails"
    charset="utf-8"
    type="html">  
    <!--- Adding image file --->
    <cfmailparam
        file="#imageFile#"
        disposition="inline"
        contentID="#imageID#"
        type="image/gif">  
    <h1>Sending Embedded Images in E-Mails</h1>
    <br />
    <!---  Referring image file with its ID --->
    <img src="cid:#imageID#" alt="My Photo" name="myPhoto" border="0" />
</cfmail>

Be carefull that you are delivering the image files with e-mail by using this method and you should be carefull about the mail size. If this is a bulk mail you need to be aware also about the traffic that your mail size generates. I would suggest to put inline CSSs for most of the design and use images just for branding etc. stuff such as logos etc.

If you have other methods to deliver nice looking e-mails please share with us.

 

0 responses to “Sending Embedded Images in E-Mails”

Leave a Reply





Powered by Mango Blog. Design and Icons by N.Design Studio