Reading Mail ColdFusion Help

Now that you know how to send e-mail using ColdFusion, you will look at the other side of e-mail: reading e-mail from a Post Office Protocol (POP) server. POP mail servers are a common type of service offered by Internet Service Providers for users to access their inboxes. Even if corporate e-mail systems rely on other technology to deliver mail to their users, POP is often provided as an alternate means for access ing the contents of inboxes.
POP mail servers can be accessed using all of today’s common e-mail software, indue ing Netscape Communicator, Microsoft Outlook Express, Eudora, and Pegasus Mail . .In this chapter, you will look at how you can use the CFPOP tag to access the contents  user’s inbox, and then make those contents accessible through a Web page. After learning the basics of the tag, you will combine this knowledge with what you learned in the preceding chapter about the CFMAIL tag to create a Web-based e-mail system that enables users to access their inboxes through a standard Web browser.

Using the CFPOP Tag

The CFPOP tag provides all the functionality needed to access the contents of an inbox OJ a POP server-This functionality includes the ability to:

• Obtain a complete or partial list of message headers
• Obtain the header and contents of one or more messages
• Download and save attachments from messages

The first step in using the CFPOP tag is to understand the information needed to access a POP server. The following attributes are necessary in order to use the CFPOP tag successfully:

SERVER Specifies the host name or IP address of the POP server. Without complete host name (such as mail .domain. name) or a complete IP address for the host (such as 10.10.10.10 (I would use a more clear IP adddress I find that the- 10.10.10.10 type addresses are easier for readers without networking backg rounds. AED}), it is impossible to connect to a Pop server.

USERNAME Specifies the mail usernamefor the inboxbeing accessed. This may be diferent from the username they use to log into their workstation in a corporate enviror ment or the username they use to establish a dial-up connection with their Internet provid.er. Using the CFPOP tag, you can access a single user’s inbox. To access multiple users’ inboxes, you need to use the CFPOP tag once for each user. The ColdFusion dO< umentation for the CFPOP tag refers to the ability to create an anonymous Pop COI\ne( tion; although this is possible, few, if any, POP servers you will work with wilfalJow  you to use an anonymous connection to achieve any practical results. Therefore, you will want to connect to a POP server as a specific user.

PASSWORD Specifies the password for the mail username indicated by the USERNAMEattribute. For example, to access the inbox of use rl on the mail server mail . domain .name by using the password passl, you would use the following basic attributes to the CFPOPtag:

<CFPOP SERVER-‘mail.domain.name’ USERNAME-‘user!’ PASSWORD-‘pass!’>

In addition to specifying the server and user information for the inbox, it is important to specify the action to perform after you are connected to the server. You do this by using the ACTIONattribute, which takes three possible values:

GetHeaderOnly Retrieves a partial or complete list of message headers without the content of the messages.

GetA11 Retrieves the header and content of one or more messages (optionally including attachments, as you will see later in the “Handling Attachments” section). Delete Deletes one or more messages from the inbox on the pop server.

Accessing a List of Messages in an Inbox

The default action, if none is specified, is for the CFPOPtag to retrieve a list of message headers from the inbox.

For instance, consider the following tag:

<CFPOP·SERVER-‘mail.domain.name’ USERNAME-‘ user!’ PASSWORD-‘ pass!’ ACTlOH-‘GetHeaderOnly’>

This causes ColdFusion to connect to the pop server ma; 1 . domain. name, log in as userl with the password passl, and retrieve the message headers for all the messages stored in the user’s inbox.

Of course, after this information is retrieved, it begs the question: What can you do with it now? ,

As with the results of the CFQUERYtag, the (FPOP tag requires that the retrieved data be named using the NAMEattribute. Once named, the data can be manipulated and displayed using the CFOUTPUTand (FU)OP tags just as you did in Chapter 3, “Getting Data from a Database.”

Therefore, to make your tag complete, you need to add the NAMEattribute: <CFPOP SERVER-‘mail.domain.name’

SERNAME-‘user!’ PASSWORD-‘pass!’
ACTlON-‘GetHeaderOnly’ NAME-‘mail’>

After you have named the results, you can access all the data in the result set through common tags such as CFOUPUTorCFLOOP.
As you will recall from our discussion of the results of database queries in Chapter 3, result sets consist of multiple rows of multiple columns (or fields) where each row represents a single result set. Data is returned by the CFPOPtag in much the same way: Each row represents a message and each column represents a field in the header of the message (when using the GetHeaderOnly action).
The following header fields are made available in the result set when using the GetHeade rOn1y action:

DATE    The date of the message as a date object
FROM   The contents of the message’s From line
MESSAGE NUMBER   The number of the message in the inbox
REPLYTO  The contents of the message’s ReplyTo line
SUBJECT  The contents of the message’s Subject line
CC  The contents of the message’s Cc line
TO  The contents of the message’s To line
HEADER.The complete contents of the message’s header in a single field In addition, the RecordCoLint variable can be used to ascertain the number of messages in the result set, just as it was used for the results of database queries. Listing 22.1 shows how this can be put together in a small example-displaying the contents of an inbox as a Web page.

Posted on November 14, 2015 in Reading Mail

Share the Story

Back to Top
Share This