CFMail

Sends an e-mail message that optionally contains query output, using an SMTP server.

Line No Coding
1 <cfmail
2   from = "sender"
3   cc = "copy_to"
4   bcc = "blind_copy_to"
5   subject = "msg_subject"
6   replyto = "reply_to_addr"
7   failto = "fail_message_addr"
8   username = "user name"
9   password = "password"
10   wraptext = "column number"
11   to = "recipient"
12   charset = "character encoding"
13   type = "msg_type"
14   mimeattach = "path"
15   query = "query_name"
16   group = "query_column"
17   groupcasesensitive = "yes" or "no"
18   startrow = "query_row"
19   maxrows = "max_msgs"
20   server = "serverspecs"
21   port = "port_id"
22   mailerid = "headerid"
23   timeout = "seconds"
24   spoolenable = "yes" or "no">
25 </cfmail>


ColdFusion MX 6.1:

  • Added the following attributes: charset, failto, replyto, username, password and wraptext.
  • Added support for multiple mail servers in the server attribute.
  • Added several configuration options to the ColdFusion MX Administrator Mail Settings page.

ColdFusion MX: Added the SpoolEnable attribute.

AttributeReq/OptDefaultDescription
to Required   Message recipient e-mail addresses.
  • Static address. For example, "support@macromedia.com"
  • Variable that contains an address. For example, "#Form.Email#".
  • Name of a query column that contains an address. For example, "#EMail#". An e-mail message is sent for each returned row.
from Required   E-mail message sender:
  • A static string; for example, "support@mex.com"
  • A variable; for example, "#GetUser.EMailAddress#"

This attribute does not have to be a valid internet address; it can be any text string.

cc Optional   Address(es) to which to copy the message.
bcc Optional   Address(es) to which to copy the message, without listing them in the message header.
subject Required   Message subject. Can be dynamically generated. For example, to send messages that give customers status updates, "Status of Order Number #Order_ID#".
replyto Optional   Address(es) to which the recipient is directed to send replies.
failto Optional   Address to which mailing systems should send delivery failure notifications. Sets the mail envelope reverse-path value.
username Optional   A user name to send to SMTP servers that require authentication. Requires a password attribute.
password Optional   A password to send to SMTP servers that require authentication. Requires a username attribute.
wraptext Optional Do not wrap text 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.
charset Optional Character encoding selected in ColdFusion MX Administrator Mail page; default is UTF-8 Character encoding of the mail message, including the headers. The following list includes commonly used values:
  • utf-8
  • iso-8859-1
  • windows-1252
  • us-ascii
  • shift_jis
  • iso-2022-jp
  • euc-jp
  • euc-kr
  • iso-2022-kr
  • big5
  • hz-gb-2312
  • euc-cn
  • utf-16

For more information on character encodings, see:
www.w3.org/International/O-charset.html.

type Optional text/plain MIME type of the message. Can be a valid MIME media type or one of the following:
  • text specifies text/plain type
  • plain specifies text/plain type
  • html specifies text/html type

For a list of all registered MIME media types see www.iana.org/assignments/media-types/

MIMEAttach Optional   Path of file to attach to message. Attached file is MIME-encoded. ColdFusion attempts to determine the MIME type of the file; use the cfmailparam tag to send an attachement and specify the MIME type.
query Optional   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.
group Optional CurrentRow 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.
groupCase
Sensitive
Optional No Boolean. Whether to consider case when using the group attribute. To group on case-sensitive records, set this attribute to Yes.
startRow Optional 1 Row in a query to start from.
maxRows Optional   Maximum number of messages to send when looping over a query.
server Optional   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 ColdFusion MX Administrator. A value here overrides the Administrator. A value that includes a port specification overrides the port attribute. See the Usage section for details.
port Optional   TCP/IP port on which SMTP server listens for requests (normally 25). A value here overrides the Administrator.
mailerID Optional ColdFusion MX Application Server Mailer ID to be passed in X-Mailer SMTP header, which identifies the mailer application.
timeout Optional   Number of seconds to wait before timing out connection to SMTP server. A value here overrides the Administrator.
spoolEnable Optional   Specifies whether to spool mail or always send it Immediately. Overrides the ColdFusion MX Administrator Spool mail messages to disk for delivery setting.
  • Yes: Saves a copy of the message until the sending operation is complete. Pages that use this option might run slower than those that use the No option.
  • No: Queues the message for sending, without storing a copy until the operation is complete. If a delivery error occurs when this option is No, ColdFusion generates an Application exception and logs the error to the mail.log file.

Sends a mail message to the specified address. Mail messages can include attachments. The tag body can include CFML code to generate mail output. The cfmailparam and cfmailpart tags can only be used in the cfmail tag body.

Mail messages can be single or multipart. If you send a multi-part mail message, all message content must be in cfmailpart tags; ColdFusion ignores multipart message text, text that is not in cfmailpart tags.

Note: The cfmail tag does not make copies of attachments when spooling mail to disk. If you use the cfmail tag to send a message with an attachment with spooling enabled and you use the cffile tag to delete the attachment file, ColdFusion might not send the mail because the mailing process might execute after the file was is deleted. (When this happens, the mail log includes a FileNotFound exception and the e-mail is not sent.) You can prevent this problem by setting SpoolEnable="No" in the attribute or disabling spooling in the ColdFusion MX Administrator. Disabling spooling causes the e-mail to be delivered immediately.

 

Mail addressing

Mail addresses can have any of the following forms:

FormatExample
user@server rsmith@company.com
<user@server> <rsmith@company.com>
DisplayName <user@server> Rob Smith <rsmith@company.com>
"DisplayName" <user@server> "Rob Smith" <rsmith@company.com>
user@server (DisplayName) rsmith@company.com (Rob Smith)

Specifying mail servers
The
server attribute can specify one or more mail servers.

Note: If you specify multiple mail servers in ColdFusion MX Standard, the cfmail tag uses only the first server in the specification. ColdFusion logs a warning message to the mail log file and ignores the additional servers.

For each server, you can optionally specify a username, password, and port. These values override the corresponding attributes, if any. The server attribute has the following format:

[user:password@]server[:port],[user:password@]server[:port],....

For example, the following line specifies one server, mail.myco.com that uses the default port and no user or password, and a second server with a user, password, and specific port:

server=mail.myco.com,mail_admin:adm2qzf@mail2.myco.com:24

When you specify multiple mail servers in ColdFusion Enterprise, ColdFusion tries the available servers in the order they are listed until it connects to a server. ColdFusion does not try to connect to a server that was unavailable in the last 60 seconds.


Sample Coding 1:


Sample Coding 2:


  • 0 A felhasználók hasznosnak találták ezt
Hasznosnak találta ezt a választ?

Related Articles

ColdFusion Page Encoding

In order to show the characters other than the English characters on your website, you may need...

Using Custom Tags in Cold Fusion

Custom tags(.cfm) do not need to be registered on the server. They can be...