User Guide

Chapter 13: Sending and Receiving Email 207
Sending SMTP mail with CFMAIL
The CFMAIL tag provides support for sending SMTP email from within ColdFusion
applications. The CFMAIL tag is similar to the CFOUTPUT tag, except that CFMAIL
outputs the generated text as SMTP mail messages rather than to a page. You can use
all the attributes and commands that you use with CFOUTPUT with CFMAIL as well.
To send a simple email message:
1. Create a new file in Studio.
2. Modify the file so that it appears as follows:
<HTML>
<HEAD>
<TITLE>Sending a simple email</TITLE>
</HEAD>
<BODY>
<H1>Sample email</H1>
<CFMAIL
FROM="Sender@Company.com"
TO="#URL.email#"
SUBJECT="Sample email"
>
This is a sample email to show basic email capability.
</CFMAIL>
The email was sent.
</BODY>
</HTML>
3. Save the file as sendmail.cfm in myapps under the Web root directory.
4. Open your browser and enter the URL that contains the file. Replace
myname@mycompany.com with you email address. For example,
http://localhost/myapps/sendmail.cfm?email=myname@mycompany.com
The template sends the email to you, through your SMTP server.
Samples uses of CFMAIL
An application page with the CFMAIL tag dynamically generates email messages based
on the tag’s settings. Some of the things you can accomplish with CFMAIL are:
Send a mail message whose recipient and contents are determined by data the
user enters in an HTML form.
Use a query to send a mail message to a database-driven list of recipients.