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

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

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

cfmail Attribute Reference


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


Email address(es) to which to copy the message


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

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.

Default: false

CF 11+ Toggles email message encryption


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


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


Message sender email address.


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.


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


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.


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


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


Password of the keystore


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


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


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.


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


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

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 Values:
  • highest
  • urgent
  • high
  • normal
  • low
  • lowest
  • non-urgent


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.


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


Tells ColdFusion to remove any attachments after successful mail delivery.


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


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.


Mail will be signed when set to true


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

Default: 1

Row in a query to start from.


Message subject. Can be dynamically generated.


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


Message recipient email addresses.

Default: text/plain

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


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


Whether to use Secure Sockets Layer.


Whether to use Transport Level Security.


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

Send basic email message

The SMTP server details are provided through the Administrator.

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

Send basic email message overriding default SMTP server

The SMTP server details are provided in code.

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

Send email messages using a query

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.

Script syntax using new mail()

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

Script syntax using function call

CF 11+ Send basic email using function call.

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

Fork me on GitHub