ColdFusion 9.0 Resources |
Getting item attachmentsTo get the attachments to an Exchange contact, event, message, or task, use a ColdFusion Exchange tag with a getAttachments action. Also specify the following information in the tag:
The following ColdFusion Exchange tag gets all attachments to the message identified by the theUID variable, saves them in the C:/temp/cf_files/attachments directory, and stores information about the attachments in the attachInfo structure: <cfexchangemail action="getattachments" connection="myconn1" uid="#theUID#" name="#attachInfo#" attachmentPath="C:/temp/cf_files/attachments" generateUniqueFilenames="true"> To get message attachments, you must have the UID of the message and know that the message has attachments. Use a ColdFusion Exchange tag, such as cfexchangemail, with the get action to determine this information. When the tag completes processing, the query specified by the name attribute includes the following columns:
You can use these fields in your decision logic that determines whether to get attachments for a message and determines the message UID. The following example gets the attachments to all mail messages from docuser2 in the last week. It places each message’s attachments in a directory whose name is the hexadecimal part of the message UID. For each message with attachments, the application reports subject and date of the message, followed by a table listing the message’s attachments. The table includes the attachment name, MIME type, and size. Notice that if a message has multiple attachments with the same name, the attachment information query always lists the attachments with their original, duplicate names, even if you specify generateUniqueFilenames="true". The generateUniqueFilenames attribute only affects the names of the files on disk. The attachmentFilePath column of the attachment information structure does have the unique filenames, however. <cfset rightNow = Now()> <cfset lastWeek = DateAdd("d","-7", rightNow)> <cfexchangeconnection action="open" username ="#user1#" password="#password1#" server="#exchangeServerIP#" connection="conn1"> <cfexchangemail action="get" folder="Inbox/MailTest" name="weeksMail" connection="conn1"> <cfexchangefilter name="FromID" value="docuser2"> <cfexchangefilter name="TimeSent" from="#lastWeek#" to="#rightNow#"> </cfexchangemail> <cfloop query="weeksMail"> <cfif weeksmail.HasAttachment> <!--- The UID is surrounded in <> characters and has an @ character. Extract the hexadecimal number part for use as a directory name. ---> <cfset atpos=Find('@', weeksMail.UID)> <cfset shortUID=Mid(weeksMail.UID, 2, atpos-2)> <cfexchangemail action="getAttachments" connection="conn1" folder="Inbox/MailTest" uid="#weeksMail.uid#" name="attachData" attachmentPath="C:/temp/cf_files/attachments/#shortUID#" generateUniqueFilenames="true"> <cfoutput> Directory #shortUID# contains these attachments to the following message:<br /> Subject: #weeksMail.Subject#<br /> Sent: #dateFormat(weeksmail.TimeSent)#<br /> <cftable query="attachData" colheaders="true"> <cfcol header="Filename" text="#attachmentFilename#"> <cfcol header="Size" text="#size#"> <cfcol header="MIME type" text="#mimeType#"> </cftable> </cfoutput> </cfif> </cfloop> <cfexchangeconnection action="close" connection="conn1"> |