cfmail

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

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

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

Attribute Reference for the cfmail tag

bcc

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

cc

Required: No
Email address(es) to which to copy the message

charset

Required: No
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

debug

Required: No
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.

encrypt

Required: No
Default: false
CF 11+ Toggles email message encryption

encryptionalgorithm

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

failto

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

from

Required: Yes
Message sender email address.

group

Required: No
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

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

keyalias

Required: No
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

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

keystore

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

keystorepassword

Required: No
Password of the keystore

mailerid

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

maxrows

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

mimeattach

Required: No
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

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

port

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

priority

Required: No
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

query

Required: No
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

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

remove

Required: No
Tells ColdFusion to remove any attachments after successful mail delivery.

replyto

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

server

Required: No
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

Required: No
Mail will be signed when set to true

spoolenable

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

startrow

Required: No
Default: 1
Row in a query to start from.

subject

Required: Yes
Message subject. Can be dynamically generated.

timeout

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

to

Required: Yes
Message recipient email addresses.

type

Required: No
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

username

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

usessl

Required: No
Whether to use Secure Sockets Layer.

usetls

Required: No
Whether to use Transport Level Security.

wraptext

Required: No
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="recipient@example.com" from="sender@example.com" subject="Example email">
  Your Email Message!!
</cfmail>

Send basic email message overriding default SMTP server

The SMTP server details are provided in code.

<cfmail to="recipient@example.com" from="sender@example.com" subject="Example email" server="smtp.example.com" port="25" username="myUsername" password="myPassword">
  Your Email Message!!
</cfmail>

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 = "receipient@example.com", lastname = "Doe", firstname = "John" }) />

<cfmail to="#recipient#" from="sender@example.com" subject="Example email" query="myQuery">
  Dear #lastname#,

  Text here, containing any variable in the myQuery scope.
</cfmail>

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 = "recipient@example.com",
  from = "sender@example.com",
  subject = "Example email",
  body = mailBody
);

// Send
mailService.send();

Script syntax using function call

CF 11+ Send basic email using function call.

cfmail( to = "recipient@example.com", from = "sender@example.com", subject = "Example email" ) { WriteOutput( "Your Email Message!!" ); }

Fork me on GitHub