Skip to main content
Inspiring
October 29, 2013
Answered

Dynamic Image As A email Signaure

  • October 29, 2013
  • 1 reply
  • 1241 views

Good Day All.

I have the following code the will randomly get an image from a folder.

It works Great.

Now what i would like to do is add that image as an inline image in my email signature.

eg

<img src="http://websiteadd/getsingle.cfm">

However this does not work.

here is the code of the CFM page.

<cfset imagesFolder = "#dirlocation##dirspace#images#dirspace#stock#dirspace#temp" />

<!--- code to look in directory, choose one image at random --->

<cfdirectory directory="#dirlocation##dirspace#images#dirspace#stock#dirspace#temp" filter="*.jpg" name="getPics" action="list"/>

<cfset maxrows = getPics.recordCount/>

<cfset startRow = randRange(1, maxrows)/>

<!--- if one or more photos was found --->

<cfif maxrows gt 0>

    <div class="showPic">

    <cfoutput query="getPics" startrow="#startRow#" maxrows="1">

<cfheader name="content-disposition" value="attachment; filename=#name#.jpg" />

<cfcontent file="#dirlocation##dirspace#images#dirspace#stock#dirspace#temp#dirspace##name#" type="image/jpg" />

        <!---<cfimage action = "writeToBrowser" source="../images/stock/temp/#name#" format="jpg" />

        <img src="../images/stock/temp/#name#"/>--->

    </cfoutput>

</cfif>

Is there anyway to do this.

Regards

    This topic has been closed for replies.
    Correct answer tribule

    If your IMG tag always shows an image, then any HTML email sent via CFMAIL should work fine, BUT (and it's a big BUT) you have no control over the client who receives the email. They may refuse HTML emails, or they may block IMG tags (for privacy concerns). When you said "However this does not work" what did you mean? Please explain.

    Creating a HTTP connection from the email to the image is also undesirable. It's probably better to embed the image, like this using a "data:" URL:

    <cfset ImgFile  =  "d:\somefolder\images\myimage.png">

    <cfset  ImgHeader = "image/png;charset=utf-8;base64">

    <cfset  ImgData = ToBase64(FileReadBinary(ImgFile), "utf-8")>
    <cfoutput>

    <img src="data:#ImgHeader#,#ImgData#"  alt="sig">

    </cfoutput>

    The data: URL includes the actual image within the IMG tag, so no outbound HTTP request to the image is required.

    1 reply

    Legend
    October 29, 2013

    You did not say how you are placing the image into the email. Are you using <cfmail> for example? Or, are you talking about a HTML email sent with a client such as Outlook? Please let us know.

    Inspiring
    October 29, 2013

    I agree that would help.

    Attaching via CFmail will not be a problem at all.

    I would like to atach it to the likes of outlook and kmail signatures.

    So that when i send an email from kmail it will attach a random image to the mail.

    I hope that helps

    tribuleCorrect answer
    Legend
    October 29, 2013

    If your IMG tag always shows an image, then any HTML email sent via CFMAIL should work fine, BUT (and it's a big BUT) you have no control over the client who receives the email. They may refuse HTML emails, or they may block IMG tags (for privacy concerns). When you said "However this does not work" what did you mean? Please explain.

    Creating a HTTP connection from the email to the image is also undesirable. It's probably better to embed the image, like this using a "data:" URL:

    <cfset ImgFile  =  "d:\somefolder\images\myimage.png">

    <cfset  ImgHeader = "image/png;charset=utf-8;base64">

    <cfset  ImgData = ToBase64(FileReadBinary(ImgFile), "utf-8")>
    <cfoutput>

    <img src="data:#ImgHeader#,#ImgData#"  alt="sig">

    </cfoutput>

    The data: URL includes the actual image within the IMG tag, so no outbound HTTP request to the image is required.