Copy link to clipboard
Copied
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
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 =
...Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
OK it does work.
I gathered kmail would show me the image inline when i say new.
but if i hit send the receiver does get the image.
Thanks very much for yu r help. but it seems it was working all the time
Copy link to clipboard
Copied
I find the best approach isto use the embedded image code above. That gets the image in most email clients, e.g. Outlook etc. Remember too that just because you can see the image, it does not mean others definitively can Test it in Gmail, Hotmail and Outlook etc and see what results you get.