Example 7.2: Creating HTML Email

Team-Fly    

ColdFusion® MX: From Static to Dynamic in 10 Steps
By Barry Moore
Table of Contents
Step 7.  Using Email with ColdFusion MX


In this example, we are going to create an HTML newsletter that we will email to our employees.

  1. Open your text editor and enter the code in Listing 7.3 or open the HTMLEmail.cfm file from the CompletedFiles\Examples\Step07 folder.

    Listing 7.3 HTMLEmail.cfm

    [View full width]

     <!--- File:         HTMLEmail.cfm  Description:  Demonstrate the use of HTML email  Author:  Created:  --->  <HTML>    <HEAD>        <TITLE>HTML Email</TITLE>    </HEAD>    <BODY>    <!--- insert your email address and SMTP server settings              in the tag below --->    <CFMAIL TO="your.email.address.here"            FROM="admin@work.com"            SUBJECT="This Month's Newsletter"            SERVER="your.smtpserver.here"            TYPE="HTML">      <HTML>        <BODY>          <!--- table for content --->            <TABLE CELLSPACING="10" WIDTH="500">              <TR ALIGN="center">                <TD BGCOLOR="##6699CC" COLSPAN="2" STYLE="font-family: sans-serif;  graphics/ccc.giffont-size: 14pt; color: White;">My Company Newsletter</TD>              </TR>              <TR>                <TD>                  <FONT STYLE="font-weight: bold; font-family: sans-serif; font size: 12pt;  graphics/ccc.gifcolor: ##333399;">                    Welcome Mark Morton                  </FONT>                  <P>Mark Morton joins the My Company team this week as our new Senior  graphics/ccc.gifNetwork Engineer. Mark has a great deal of experience with Windows 2000, NTand SQL Server  graphics/ccc.gifas well as Citrix. If you see Mark around this week say hello and make him feel welcome.  graphics/ccc.gifWe are glad to have him on board                  </P>                </TD>                <TD>                  <FONT STYLE="font-weight: bold; font-family: sans-serif; font size: 12pt;  graphics/ccc.gifcolor: ##333399;">                    Social Club Drinks                    </FONT>                  <P>It is that time of the month again. The social club has arranged a My  graphics/ccc.gifCompany drinks night at City Rowers Pub. City Rowers is located in Eagle Street Plaza  graphics/ccc.gifover looking the river. Festivities begin at 6:00pm and entry is free for Social Club  graphics/ccc.gifmembers.   See you there.                  </P>                 </TD>                 </TR>                    <TR ALIGN="center">                      <TD BGCOLOR="##6699CC" COLSPAN="2">&nbsp;</TD>                    </TR>               </TABLE>           </BODY>         </HTML>    </CFMAIL>    <P>This month's newsletter has been sent</P>    </BODY>  </HTML>
  2. Substitute your email address in the TO attribute of the <CFMAIL> tag and enter the server name for your SMTP server in the SERVER attribute of the <CFMAIL> tag.

  3. Save the file as HTMLEmail.cfm in your Examples\Step07 folder.

    Notice that the email message contains the proper <HTML> and <BODY> tags. It does not require <HEAD> tags unless you are including items that would normally be included in this section, such as JavaScript functions or cascading style sheet information. Also note that we have escaped all the # symbols in our color-code information.

  4. Browse to the HTMLEmail.cfm page to send the email.

  5. Open your email client to check for delivery. After the email has arrived, you should see a message similar to the one in Figure 7.7.

    Figure 7.7. The HTML newsletter email display.

    graphics/07fig07.gif

In the following section, we will see how an email such as this can be bulk emailed to all employees at once.


    Team-Fly    
    Top
     



    ColdFusion MX. From Static to Dynamic in 10 Steps
    ColdFusion MX: From Static to Dynamic in 10 Steps
    ISBN: 0735712964
    EAN: 2147483647
    Year: 2002
    Pages: 140
    Authors: Barry Moore

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net