ColdFusion MX: From Static to Dynamic in 10 Steps

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" /books/4/16/1/html/2/images/ccc.gif" alt="graphics/ccc.gif" width="14" height="9" layout="responsive" class="mb4 mx3">font-size: 14pt; color: White;">My Company Newsletter</TD> </TR> <TR> <TD> <FONT /books/4/16/1/html/2/images/ccc.gif" alt="graphics/ccc.gif" width="14" height="9" layout="responsive" class="mb4 mx3">color: ##333399;"> Welcome Mark Morton </FONT> <P>Mark Morton joins the My Company team this week as our new Senior Network Engineer. Mark has a great deal of experience with Windows 2000, NTand SQL Server as well as Citrix. If you see Mark around this week say hello and make him feel welcome. We are glad to have him on board </P> </TD> <TD> <FONT /books/4/16/1/html/2/images/ccc.gif" alt="graphics/ccc.gif" width="14" height="9" layout="responsive" class="mb4 mx3">color: ##333399;"> Social Club Drinks </FONT> <P>It is that time of the month again. The social club has arranged a My Company drinks night at City Rowers Pub. City Rowers is located in Eagle Street Plaza over looking the river. Festivities begin at 6:00pm and entry is free for Social Club members. 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.

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
     

    Категории