Sending Email Messages

Before you set up ColdFusion to send email messages, you must have access to an SMTP email server. Also, before you run application pages that refer to the email server, you may want to configure the ColdFusion Administrator to use the SMTP server so that you don't have to hard-code it in your application.

Note To configure ColdFusion for email:
  1. Open the Mail page in the ColdFusion Administrator.
  2. In the Mail Server box, enter the address of the SMTP mail server you want ColdFusion to use.
  3. Normally, you leave the Server Port and Connection Timeout settings at their default values, unless you need different settings.
  4. Click Apply to save the settings.
  5. To verify server settings, click the Verify button to make sure ColdFusion can access your mail server.

See Administering ColdFusion Server or more information on the Administrator's mail settings.

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.

Note 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.