User Guide

216 Developing Web Applications with ColdFusion
<BODY>
<H2>This example retrieves message header,
body, and all attachments:</H2>
<CFPOP SERVER="mail.company.com"
USERNAME=#username#
PASSWORD=#password#
ACTION="GetAll"
ATTACHMENTPATH="c:\attachdir"
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>
Body: #HTMLCodeFormat(Sample.BODY)# <BR>
Header: #HTMLCodeFormat(Sample.HEADER)# <BR>
</CFOUTPUT>
</BODY>
</HTML>
3. Change the following line so that it refers to a valid POP mail server, as well as a
valid user name and password:
<CFPOP SERVER="mail.company.com"
USERNAME=#username#
PASSWORD=#password#
4. Save the file as attach.cfm in myapps under the Web root directory.
Note To avoid duplicate file names when saving attachments, use the
GENERATEDUNIQUEFILENAMES attribute of CFPOP and set it to Yes.
Deleting messages
By default, retrieved messages are not deleted from the POP mail server. If you want to
delete retrieved messages, you must set the ACTION attribute to Delete.
Note Once a message is deleted, it’s gone for good.
The MESSAGENUMBER attribute returned by all CFPOP retrievals contains the
message number you need to pass back to the POP mail server to have the
corresponding message deleted. A few notes:
Note Message numbers are reassigned at the end of every POP mail server
communication that contains a delete action. For example, if four
messages are retrieved from a POP mail server, the message numbers