Generating Recipient Lists from a Query ColdFusion Help

This is where dynamic data becomes extremely useful with the CFMAIL tag. Let’s consider the guest-book list but assume that this time you want to send a form message to each person on the list Again you use the QUERY attribute of the CFMAIL tag, but you use your dynamic data in a slightly different way:

In this example, you use the column Email from your query result to generate an ~mail to each individual in the Contacts table. For each row of your table, separate e-mail Will be addressed to the e-mail addresses stored in the Email field. You can take this even further by personalizing each outgoing message. Consider the following CFMAIL segment, which builds on the preceding example:

following CFMAIL segment, which builds on the preceding example:

Now what’s happening is only slightly more complex. Not only is each row of the query result used to create a separate message to a different contact, but for each message, the Namefield of the row is used to personalize the text of the message. Let’s look at an example. Say you have two rows in your query result.

In this case, two e-mails will be generated. The first, to SomeoneOsome. domai n, will be personally addressed to Some One and the second, to AnotherOanother. domai n, will be personally addressed to Someone Else.

At this point you should note three other attributes of the CFMAILtag that can be used with the QUERYattribute:

MAXROWS Specifies the maximum number of query rows to process. For instance, in the preceding example of sending a message to multiple people from a query result, if the result contained 1.0rows but MAXROWwSas set to 5, e-mail would be generated for only the recipients represented by the first five rows of the query result.

STARTROW Specifies the first row to process in a query result. Again, in our last example, if the result contained 10 rows but STARTROWwas set to 6, e-mail would be generated only for the recipients represented by rows 6 through 10.

GROUP Specifies the column name on which to perform grouping. For example, if you specify Email as your group’.column and the same e-mail address is repeated in . two rows, then only one e-mail will be generated for this address, effectively grouping multiple rows with the same e-mail address into one result.

GROUPCASESENSITIVE Specifies whether grouping with the GROUPattribute should be case sensitive. This attribute takes TRUEor FALSEas its value and TRUEis the default value. This attribute behaves in the same way as it does for the CFOUTPUT tag discussed in Chapter 12, “Grouping, Nesting, and Formatting Outputs.”


The CFMAILPARAtaMg, new in ColdFusion 4.5, can be used between the opening and closing <CFMAIL>and </CFMAIL>tags. This tag can be used for two

• Attaching more than one file as an alternative to the MIMEATIACH attribute of the CFMAILtag.
• Adding massage headers to your outgoing e-mail.

To add a mail message using the CFMAILP ARAM tag, use the FILE attribute to-specify the file’s path and name.

You can use multiple CFMAILP ARAM tags to attach multiple files:

CBlAIL To-‘MIIIy.doaIain’
from in’
SU8JECT-‘Attachlent test’>
<CFMAILPARAM FILE-‘C:\some\file.txt’>
<CFMAILPAAAM FILE-‘C:\some\otherfile.txt’)
This massage has two,attachments.

What Do We Go from Here?

In this chapter, you have learned how to use ColdFusion to take advantage of one half of the e-mail puzzle: sending e-mail using SMTP and the CFMAIL tag. In the next chapter, you will look at the other half of the puzzle: reading incoming e-mail from a pop server by using the CFPOP tag. This tag provides a means by which Web-based e-mail applications can be quickly developed and used for numerous other  including generating searchable e-mail inboxes on pop servers.

After learning the mechanics of the CFPOPtag, you will combine that knowledge with the information you have learned in this chapter to put together a full-blown, based, e-mail application.

Posted on November 14, 2015 in Sending Mail

Share the Story

Back to Top
Share This