Using the CF_Mail tag.

We are now enabling a CFX tag to enable customers another option when sending mail.  There really only needs to be a minor change in your CFMail tag in order for the new tag to work.  The new tag is 'CF_mail'.  This tag uses IIS to handle mail and doesn't have the issues that some of our customers have experienced with CFMail slowing the CF service or bottle necking the mail queue.  Below is examples of how to code for the 'CF_Mail' tag.

Send An Email

      The following code will send an email to bob@jones.com, fred@jones.com, and buddy@jones.com 



<CF_MAIL
   TO="bob@jones.com,fred@jones.com,buddy@jones.com"
   FROM="Billy Jones <billy@jones.com>"
   SUBJECT="Billy's got a new cow">
Hi, just wanted to announce that I've got a new cow!
</CF_MAIL>


Send a personalized email using a database

      The next example selects email addresses from a query, and dynamically makes the TO list using CF's ValueList() function. This example will also send a multi-part message, because both TEXTMESSAGE and HTMLMESSAGE is specified. This will also generate a verbose logfile with the date in the filename. 



<cfquery name="qry" datasource="ds">
   SELECT email, name
   FROM farmers
</cfquery>

<CF_MAIL
   QUERY="qry"
   FROM="Billy Jones <billy@jones.com>"
   TO="email"
   SUBJECT="Hey %name% I got a new cow"
   VERBOSE="1"
   TOKENS="1"
   TYPE="HTML"
   TEXTMESSAGE="Hi %name%, just wanted to announce that I've got a new cow.">
Hi %name%, just wanted to announce that <b>I've got a new cow</b>.
</CF_MAIL>

      The following QUERY could be used to generate an address that looks like First Last <email@address.com> with fields in a database named FirstName, LastName, and Email. Using this format recipients will see their name in the TO box of the message, instead of just the email address. 




<cfquery name="qry" datasource="ds">
   SET CONCAT_NULL_YIELDS_NULL OFF
   SELECT firstname + ' ' + lastname + ' <' + email + '>' AS Email
   FROM users
</cfquery> 

Note: SET CONCAT_NULL_YIELDS_NULL OFF is used to prevent SQL Server from making the result of the concatenation NULL if any of the fields are null. If your name, and email address fields do not allow nulls then you may remove that line. If your email address field allows NULL's and you are concatenating with a name, you should add an extra statement to the where clause that removes null addresses (eg WHERE email <> ''). The above example was designed for SQL Server, if you are running other servers check your database server's documentation.

       


Using SMTP Authentication

      Add your SMTP username and password to the SERVER attribute using the pattern user:password@server:port 



<CF_MAIL
   TO="bob@jones.com,fred@jones.com,buddy@jones.com"
   FROM="Billy Jones <billy@jones.com>"
   SERVER="billy:password@mail.server.com"
   SUBJECT="Billy's got a new cow">
Hi, just wanted to announce that I've got a new cow!
</CF_MAIL>


Using Multiple SMTP Servers

      Add a comma seperated list of mail servers in the SERVER attribute using the pattern user:password@server:port user password and port are optional 



<CF_MAIL
   TO="bob@jones.com,fred@jones.com,buddy@jones.com"
   FROM="Billy Jones <billy@jones.com>"
   SERVER="smtp1.server.com,billy:password@smtp2.server.com,smtp3.server.com:2525,billy:pwd@smtp4.server.com:25"
   SUBJECT="Billy's got a new cow">
Hi, just wanted to announce that I've got a new cow!
</CF_MAIL>



Sending an attachment

Use the file attribute to specify an attachment.

<CF_MAIL
   TO="bob@jones.com,fred@jones.com,buddy@jones.com"
   FROM="Billy Jones <billy@jones.com>"
   SUBJECT="Billy's got a new cow">

Hi, check out the attached picture of my new cow

    <cf_mailattachment file="c:\cow001.jpg" type="image/jpeg" name="billysCow.jpg">

</CF_MAIL>
Embeding an image in HTML Email

Use the CID attribute to embed an image into HTML message

<CF_MAIL
   TO="bob@jones.com,fred@jones.com,buddy@jones.com"
   FROM="Billy Jones <billy@jones.com>"
   TYPE="html"
   SUBJECT="Billy's got a new cow">

Hi, check out the picture of my new cow:

<img src="cid:cow" id="cow">

    <cf_mailattachment file="c:\cow001.jpg" type="image/jpeg" cid="cow">

</CF_MAIL>

Sending an alternative message part

You want to send rich text email that can be read by AOL 6.0 users

<CF_MAIL
   TO="bob@jones.com,fred@jones.com,buddy@jones.com"
   FROM="Billy Jones <billy@jones.com>"
   TYPE="html"
   TEXTMESSAGE="I got a new cow"
   SUBJECT="Billy's got a new cow">

I got a new <b>cow</b>

    <cf_mailattachment file="c:\aol.html" type="text/x-aol" alternative="true" disposition="inline">

</CF_MAIL>

Adding a custom header

Use the CF_MailAttachment tag to add a custom header to the email message.

<CF_MAIL
   TO="bob@jones.com,fred@jones.com,buddy@jones.com"
   FROM="Billy Jones <billy@jones.com>"
   SUBJECT="Billy's got a new cow">

I got a new cow

    <cf_mailheader name="X-Mailer" value="Billys Mail Server Farm">

</CF_MAIL>
Setting the message importance

You can set the Importance header to Low, Normal, or High.


<CF_MAIL
   TO="bob@jones.com,fred@jones.com,buddy@jones.com"
   FROM="Billy Jones <billy@jones.com>"
   SUBJECT="Billy's got a new cow">

I got a new cow

    <cf_mailheader name="Importance" value="High">

</CF_MAIL>
Setting the message Precedence

Its a good idea to set the precedence to bulk when sending bulk email.

<CF_MAIL
   TO="bob@jones.com,fred@jones.com,buddy@jones.com"
   FROM="Billy Jones <billy@jones.com>"
   SUBJECT="Billy's got a new cow">

I got a new cow

    <cf_mailheader name="Precedence" value="bulk">

</CF_MAIL>


Was this article helpful?

mood_bad Dislike 0
mood Like 0
visibility Views: 4427