
1195
DEVELOPING
COLDFUSION 9 APPLICATIONS
Using External Resources
Las
t
upda
te
d 8/5/2010
Sending multipart mail messages
The cfmailpart tag lets you create multipart mail messages, with each part having a different MIME type or character
set. For example, if you do not know that all recipients can interpret HTML mail messages, you can send your message
as a multipart mail with a text part and an HTML part. To do so, use two
cfmailpart
tags, one with the HTML version
of the message and one with the plain text message, as shown in the following example. To test this example, replace
the
To
attribute value with a valid e-mail address, save and run the page, and check the incoming e-mail at the address
you entered.
<cfmail from = "[email protected]" To = "[email protected]"
Subject = "Which version do you see?">
<cfmailpart
type="text"
wraptext="74">
You are reading this message as plain text, because your mail reader
does not handle HTML text.
</cfmailpart>>
<cfmailpart
type="html">
<h3>HTML Mail Message</h3>
<p>You are reading this message as <strong>HTML</strong>.</p>
<p>Your mail reader handles HTML text.</p>
</cfmailpart>
</cfmail>
Note:
In the HTML version of the message, escape any number signs, such as those used to specify colors, by using two #
characters; for example,
bgcolor="##C5D9E5"
.
Sample uses of the cfmail tag
An application page containing the cfmail tag dynamically generates e-mail messages based on the tag settings. Some
of the tasks that you can accomplish with
cfmail
include the following:
•
Sending a mail message in which the data the user enters in an HTML form determine the recipient and contents
•
Using a query to send a mail message to a database-driven list of recipients
•
Using a query to send a customized mail message, such as a billing statement, to a list of recipients that is
dynamically populated from a database
Sending form-based e-mail
In the following example, the contents of a customer inquiry form submittal are forwarded to the marketing
department. You could also use the same application page to insert the customer inquiry into the database. You
include the following code on your form so that it executes when users enter their information and submit the form:
<cfmail
from="#Form.EMailAddress#"
to="[email protected],[email protected]"
subject="Customer Inquiry">
A customer inquiry was posted to our website:
Name: #Form.FirstName# #Form.LastName#
Subject: #Form.Subject#
#Form.InquiryText#
</cfmail>