ColdFusion 9.0 Resources |
Displaying images inlineIf an HTML message includes inline images, the Exchange server saves the images as attachments. Take the following steps to display the images in the retrieved message:
The following example shows how to display a message with an inline image by retrieving the image from the attachments. <!--- Open the connection to the Exchange server. ---> <cfexchangeconnection action="open" username = "#user1#" password = "#password1#" server = "#exchangeServerIP#" connection = "testconn"> <!--- Get the mail message. ---> <cfexchangeMail action="get" connection ="testconn" name="getMail"> <cfexchangeFilter name="Subject" value="sample inline image"> </cfexchangeMail> <cfdump var="#getMail#"> <!--- The following code assumes we found only one matching message. ---> <cfoutput query="getMail"> <cfset theUID = #getMail.UID#> <cfset htmlmessage = getMail.htmlmessage> </cfoutput> <!--- Get the message attachments. ---> <CFExchangeMail action="getAttachments" UID ="#theUID#" connection="testconn" name="attachments" attachmentPath="C:\ColdFusion8\wwwroot\My_Stuff\cfexchange\Book\attachments" generateuniquefilenames="no"> <!--- Extract the image names from the mail message ---> <!--- Initialize the index into the message used in finding ---> <cfset findstart = 1> <!--- Use an index loop to find all image source entries in the message ---> <!--- This example supports up to 25 inline images ---> <cfloop index="i" from="1" to="25"> <!--- find a cid: entry ---> <cfset stringStart[i] = Find('"cid:', htmlmessage, findstart)> <!--- Exit the loop if no match was found ---> <cfif (stringstart[i] EQ 0)> <cfbreak> </cfif> <!--- Increment the string index used in finding images. ---> <cfset findstart = stringstart[i] +5 > <!--- Get text to the right of âBADCHAR˜cid:.âBADCHAR™ Using a string length of 30 should get more than the image name. ---> <cfset rightpart[i]=Mid(htmlmessage, findstart, 30)> <!--- use the ListFirst function to remove all the text starting at the quotation mark. ---> <cfset imagename[i]=ListFirst(rightpart[i], '"')> <!--- Loop over the attachments query and find the CID. ---> <cfloop query="attachments"> <!--- Replace the image name with the contents of the attachment ---> <cfif attachments.CID EQ imagename[i]> <cfset htmlmessage = Replace(htmlmessage,"cid:#imagename[i]#", "attachments/#attachments.ATTACHMENTFILENAME#")> </cfif> </cfloop> </cfloop> <h3>The full mail message</h3> <cfoutput>#htmlmessage#</cfoutput> <cfexchangeconnection action="close" connection = "testconn"> |