ActivMail - Version 2.1.0.3
ActivMail Examples
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
Embeding an image in HTML Email
Sending an alternative message part
Adding a custom header
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
ActivMail Documentation
Copyright © CFDEV.COM 2004