Sends an email message that optionally contains query output, using an SMTP server.

  <cfmail to="" from="" subject="">

 cfmail(to="", from="", subject="");

cfmail Attribute Reference

bcc string

Email address(es) to which to copy the message, without listing them in the message header.

cc string

Email address(es) to which to copy the message

charset string

The character encoding in which the text part is encoded.
  • utf-8
  • iso-8859-1
  • windows-1252
  • us-ascii
  • shift_jis
  • iso-2022-jp
  • euc-jp
  • euc-kr
  • big5
  • euc-cn
  • utf-16

debug boolean
Default: false

true: sends debugging output to standard output. By default, if the console window is unavailable, ColdFusion sends output to cf_root\runtime\logs\coldfusion-out.log on server configurations. On J2EE configurations, with JRun, the default location is jrun_home/logs/servername-out.log.
false: does not generate debugging output.
  • true
  • false

encrypt boolean
Default: false

CF 11+ Toggles email message encryption
  • true
  • false

encryptionalgorithm string

CF 11+ Algorithm to use when encrypt=true
Encryption support is provided through S/MIME.
  • RC2_CBC
  • AES128_CBC
  • AES192_CBC
  • AES256_CBC

failto string

Email address to which mailing systems should send delivery failure notifications. Sets the mail envelope reverse-path value.

from string

Message sender email address.

group string

Query column to use when you group sets of records to send as a message. For example, to send a set of billing statements to a customer, group on "Customer_ID." Case-sensitive. Eliminates adjacent duplicates when data is sorted by the specified field.

groupcasesensitive boolean

Whether to consider case when using the group attribute. To group on case-sensitive records, set this attribute to Yes.
  • true
  • false

keyalias string

Alias of the key with which the certificate and private key is stored in keystore. If it is not specified then the first entry in the keystore will be picked up.

keypassword string

Password with which the private key is stored. If it is not specified, keystorepassword will be used as keypassword as well.

keystore string

Keystore containing the private key and certificate. The supported type is JKS (java key store) and pkcs12

keystorepassword string

Password of the keystore

mailerid string

Mailer ID to be passed in X-Mailer SMTP header, which identifies the mailer application.

maxrows numeric

Maximum number of messages to send when looping over a query.

mimeattach string

Path of file to attach to message. Attached file is MIME-encoded. CFML attempts to determine the MIME type of the file; use the cfmailparam tag to send an attachement and specify the MIME type.

password string

A password to send to SMTP servers that require authentication. Requires a username attribute.

port numeric

TCP/IP port on which SMTP server listens for requests (normally 25). A value here overrides the Administrator.

priority string
Default: normal

The message priority level. Can be an integer in the range 1-5; 1 represents the highest priority, or one of the following string values, which correspond to the numeric values
  • highest
  • urgent
  • high
  • normal
  • low
  • lowest
  • non-urgent

query query

Name of cfquery from which to draw data for message(s). Use this attribute to send more than one message, or to send query results within a message.

recipientcert string

CF 11+ Path to the public key certificate of the recipient.

remove boolean

Tells ColdFusion to remove any attachments after successful mail delivery.

replyto string

Email address(es) to which the recipient is directed to send replies.

server string

SMTP server address, or (Enterprise edition only) a comma-delimited list of server addresses, to use for sending messages. At least one server must be specified here or in the CFML MX Administrator. A value here overrides the Administrator. A value that includes a port specification overrides the port attribute.

sign boolean

Mail will be signed when set to true

spoolenable boolean

Specifies whether to spool mail or always send it Immediately. Overrides the CFML MX Administrator Spool mail messages to disk for delivery setting.
  • true
  • false

startrow numeric
Default: 1

Row in a query to start from.

subject string

Message subject. Can be dynamically generated.

timeout numeric

Number of seconds to wait before timing out connection to SMTP server. A value here overrides the Administrator.

to string

Message recipient email addresses.

type string
Default: text/plain

The MIME media type of the part. Can be a can be valid MIME media type
  • plain
  • html
  • text
  • text/html
  • text/plain

username string

A user name to send to SMTP servers that require authentication. Requires a password attribute

usessl boolean

Whether to use Secure Sockets Layer.
  • true
  • false

usetls boolean

Whether to use Transport Level Security.
  • true
  • false

wraptext numeric

Specifies the maximum line length, in characters of the mail text. If a line has more than the specified number of characters, replaces the last white space character, such as a tab or space, preceding the specified position with a line break. If there are no white space characters, inserts a line break at the specified position. A common value for this attribute is 72.

Links more information about cfmail

Examples sample code using the cfmail tag

The SMTP server details are provided through the Administrator.

<cfmail to="" from="" subject="Example email">
  Your Email Message!!

The SMTP server details are provided in code.

<cfmail to="" from="" subject="Example email" server="" port="25" username="myUsername" password="myPassword">
  Your Email Message!!

Loop through database records and sends one email per row.

<cfset myQuery = queryNew( "recipient,lastname,firstname" )>
<cfset queryAddRow( myQuery, { receipient = "", lastname = "Doe", firstname = "John" }) />

<cfmail to="#recipient#" from="" subject="Example email" query="myQuery">
  Dear #lastname#,

  Text here, containing any variable in the myQuery scope.

CF 9+ The cfmail features are also available through the mail component.

savecontent variable="mailBody" {
  writeOutput( "Your Email Message!!" );

// Create and populate the mail object
mailService = new mail(
  to = "",
  from = "",
  subject = "Example email",
  body = mailBody

// Send

CF 11+ Send basic email using function call.

cfmail( to = "", from = "", subject = "Example email" ) { WriteOutput( "Your Email Message!!" ); }

Fork me on GitHub