When you use the cfpop tag with an attachmentpath attribute to specify the directory in which to store attachments, ColdFusion retrieves any attachment files from the POP server and saves them in the specified directory. The cfpop tag fills the attachmentfiles field with a tab-separated list of the locations of the attachment files. Use the cffile tag to delete these temporary files when they are no longer needed. ColdFusion MX creates the directory if it does not exist. (ColdFusion MX must have the appropriate rights on the system to create the directory.)
If a message has no attachments, the attachments and attachmentfiles columns contain empty strings.
Note: CFML does not provide a way to change the name of a mail attachment returned by cfpop before it tries to save the file. If the attachment name is invalid for the file system on which ColdFusion is running, the attachment cannot be saved.
<html> <head> <title>POP Mail Message Attachment Example</title> </head> <body> <h2>This example retrieves message header, body, and all attachments:</h2> <cfpop server="mail.company.com" username=#myusername# password=#mypassword# action="GetAll" attachmentpath="c:\temp\attachments" name="Sample"> <cfoutput query="Sample"> MessageNumber: #HTMLEditFormat(Sample.MessageNumber)# <br> To: #HTMLEditFormat(Sample.to)# <br> From: #HTMLEditFormat(Sample.from)# <br> Subject: #HTMLEditFormat(Sample.subject)# <br> Date: #HTMLEditFormat(Sample.date)# <br> Cc: #HTMLEditFormat(Sample.cc)# <br> ReplyTo: #HTMLEditFormat(Sample.ReplyTo)# <br> Attachments: #HTMLEditFormat(Sample.Attachments)# <br> Attachment Files: #HTMLEditFormat(Sample.AttachmentFiles)# <br> <br> Body:<br> #Sample.body# <br> <br> Header:<br> HTMLCodeFormat(Sample.header)# <br> <hr> </cfoutput> </body> </html>
<cfpop server="mail.company.com" username=#myusername# password=#mypassword#
Note: To avoid duplicate filenames when saving attachments, set the generateUniqueFilenames attribute of cfpop to Yes.