Retrieving messages

When you use the cfpop tag with action="GetAll", ColdFusion returns the same columns as with getheaderonly, plus the following additional columns:

If the message is multipart, the htmlbody and textbody fields contain the contents of the HTML and plain text parts, and the body field has the first part in the message. If the message has only one part, the body contains the message, and either the htmlbody or textbody field, depending on the message type, also has a copy of the message.

To retrieve entire messages:

  1. Create a ColdFusion page with the following content:
    <html>
    <head><title>POP Mail Message Body Example</title></head>
    
    <body>
    <h2>This example adds retrieval of the message body:</h2>
    <cfpop server="mail.company.com"
    	username=#myusername#
    	password=#mypassword#
    	action="GetAll"
    	name="Sample">
    
    <cfoutput query="Sample">
    	MessageNumber: #HTMLEditFormat(Sample.messageNumber)# <br>
    	To: #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>
    	Body:<br>
    	#Sample.body#<br>
    	<br>
    	Header:<br>
    	#HTMLCodeFormat(Sample.header)#<br>
    	<hr>
    	</cfoutput>
    
    </body>
    
</html>
  1. Edit the following lines so that they refer to valid values for your POP mail server, username, and password:
    <cfpop server="mail.company.com"
    	username=#myusername#
    	password=#mypassword#
    
  2. Save the file as header_body.cfm in the myapps directory under your web_root and view it in your web browser:

This example does not use a CFML function to encode the body contents. As a result, the browser displays the formatted message as you would normally see it in a mail program that supports HTML messages.


View comments in LiveDocs