To retrieve message headers without getting the messages, specify action="GetHeaderOnly"
in the cfpop
tag. Whether you use cfpop
to retrieve the header or the entire message, ColdFusion returns a query object that contains one row for each message in the specified mailbox. you specify the query object name in the cfpop
tag name
attribute. The query has the following fields:
The cfpop
tag with the getHeaderOnly
attribute retrieves any file attachments if you specify an attachmentPath
attribute; otherwise, it does not get the attachments, and the attachmentfiles column contains empty strings.
<html> <head> <title>POP Mail Message Header Example</title> </head> <body> <h2>This example retrieves message header information:</h2> <cfpop server="mail.company.com" username=#myusername# password=#mypassword# action="GetHeaderOnly" 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><br> </cfoutput> </body> </html>
<cfpop server="mail.company.com" username=#myusername# password=#mypassword#
This code retrieves the message headers and stores them in a cfpop
record set called Sample. For more information about working with record set data, see Using Query of Queries.
The ColdFusion function HTMLEditFormat
replaces characters that have meaning in HTML, such as the less than (<) and greater than (>) signs that can surround detailed e-mail address information, with escaped characters such as <
and >
.
In addition, you can process the date returned by cfpop
with ParseDateTime
, which accepts an argument for converting POP date/time objects into a CFML date-time object.
You can reference any of these columns in a cfoutput
tag, as the following example shows:
<cfoutput
> #ParseDateTime(queryname.date, "POP")# #HTMLCodeFormat(queryname.from)# #HTMLCodeFormat(queryname.messageNumber)# </cfoutput
>
For information on these ColdFusion functions, see CFML Reference.