Sending E-mail Messages

Before you set up ColdFusion to send e-mail messages, you must have access to an SMTP e-mail server. Also, before you run application pages that refer to the e-mail server, you might want to configure the ColdFusion Administrator to use the SMTP server so that you do not have to hard-code it in your application.

To configure ColdFusion for e-mail:

  1. Open the Mail/Mail Logging page of the ColdFusion Administrator Server tab.
  2. In the Mail Server box, enter the name or IP address of the SMTP mail server you want ColdFusion to use.
  3. Select the Verify Mail Server Connection check box to make sure ColdFusion can access your mail server.
  4. Leave the Server Port and Connection Timeout settings at their default values, unless you need different settings.
  5. Click Submit Changes to save the settings.

The page displays a message indicating success or failure at connecting to the server.

For more information on the Administrator's mail settings, see Advanced ColdFusion Administration.

Sending SMTP mail with cfmail

The cfmail tag provides support for sending SMTP e-mail 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. The cfmail tag supports all the attributes and commands that you use with cfoutput, including query.

To send a simple e-mail message:

  1. Create a new file in ColdFusion Studio.
  2. Modify the file so that it appears as follows:
    <html>
    
    <head>
    
      <title>Sending a simple e-mail</title>
    
    </head>
    
    
    
    <body>
    
    <h1>Sample e-mail</h1>
    
    <cfmail
    
      from="Sender@Company.com"
    
      to="#URL.email#"
    
      subject="Sample e-mail"
    
    >
    
    This is a sample e-mail to show basic e-mail capability.
    
    
    
    </cfmail>
    
    
    
    The e-mail 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; for example:
    http://localhost/myapps/sendmail.cfm?email=myname@mycompany.com
    
    

    (Replace myname@mycompany.com with your e-mail address.)

The page sends the e-mail to you, through your SMTP server.



Banner.Novgorod.Ru