Retrieving Messages

You have seen that ColdFusion can send email via the CFMAIL tag. In addition to sending email, ColdFusion can also retrieve email messages using the Post Office Protocol (POP3) via the CFPOP tag. Using this tag, ColdFusion can retrieve message headers, message contents and file attachments. In essence, this allows you to use ColdFusion to create a web-based email system, like Yahoo! Mail or Hotmail. The CFPOP tag can also create applications such as auto-responders and mailing-list managers.

Retrieving Message Headers

The CFPOP tag can retrieve just the header portion of email messages stored on a POP server. This is useful when you want to retrieve summary information such as the message title for more than one message. Retrieving just the message headers allows you to avoid the overhead associated with retrieving the entire contents of each message you retrieve. In the context of a web-based email client, this technique is used to build a list of messages in a user’s mailbox. You can retrieve the headers for a group of messages by setting the ACTION attribute of the CFPOP tag to GetHeaderOnly as shown in Example 13-9.

Example 13-9. Retrieving Message Headers

<CFPOP ACTION="GETHEADERONLY" NAME="GetMessageHeaders" SERVER="popserver.example.com" TIMEOUT="600" USERNAME="username" PASSWORD="password"> <CFOUTPUT> <H3>#GetMessageHeaders.RecordCount# messages on the server</H3> </CFOUTPUT> <TABLE BORDER="0" CELLPADDING="3" CELLSPACING="0"> <TR> <TD><B>From<B></TD><TD>&nbsp;&nbsp;</TD><TD><B>Date</B></TD> ...

Get Programming ColdFusion now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.