cfmail

Description

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

Category

Forms tags, Internet Protocol tags

Syntax

<cfmail 
  to = "recipient"
  from = "sender"
  cc = "copy_to"
  bcc = "blind_copy_to"
  subject = "msg_subject"
  type = "msg_type"
  maxrows = "max_msgs"
  mimeattach = "path"
  query = "query_name"
  group = "query_column"
  groupcasesensitive = "yes" or "no"
  startrow = "query_row"
  server = "servername"
  port = "port_id"
  mailerid = "headerid"
  timeout = "seconds"
  spoolenable = "yes" or "no"> 

See also

cfftp, cfhttp, cfldap, cfmailparam, cfpop

History

New in ColdFusion MX: the SpoolEnable attribute is new.

Attributes

Attribute Req/Opt Default Description
to
Required
 
Message recipient name(s).
  • 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#"
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#".
type
Optional
 
Extended type attributes for message. Informs receiving e-mail client that message has embedded HTML tags to process. Used only by mail clients that support HTML.
  • HTML
maxRows
Optional
 
Maximum number of messages to send.
MIMEAttach
Optional
 
Path of file to attach to message. Attached file is MIME-encoded.
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.
groupCaseSensitive
Optional
Yes
Boolean. Whether to consider case when grouping. If the query attribute specifies a query object that was generated by a case-insensitive SQL query, set this attribute to No, to keep the record set intact.
startRow
Optional
1
Row in a query to start from.
server
Optional
 
SMTP server address to use for sending messages. Server must be specified here or in Administrator. A value here overrides the Administrator.
port
 
-1
TCP/IP port on which SMTP server listens for requests. This is normally 25.
mailerID
Optional
ColdFusion Application Server
Mailer ID to be passed in X-Mailer SMTP header, which identifies the mailer application.
timeout
Optional
-1
Number of seconds to wait before timing out connection to SMTP server.
spoolEnable
Optional
Yes
  • Yes: Saves a copy of the message until the sending operation is complete. May be slower than the No option.
  • No: Queues the message for sending, without storing a copy until the operation is complete.

Example

<h3>cfmail Example</h3>
<p>This view-only example shows the use of cfmail. 
<!--- 
<cfif IsDefined("form.mailto")>
  <cfif form.mailto is not "" 
        AND form.mailfrom is not "" 
        AND form.Subject is not "">
    <cfmail to = "#form.mailto#"
        from = "#form.mailFrom#"
        subject = "#form.subject#">
        This message was sent by an automatic mailer built with cfmail:
        = = = = = = = = = = = = = = = = = = = = = = = = = = =
        #form.body#
    </cfmail>  
    <h3>Thank you</h3>
    <p>Thank you, <cfoutput>#mailfrom#: your message, #subject#, has
        been sent to #mailto#</cfoutput>.
  </cfif>  
</cfif>
<p>
<form action = "cfmail.cfm">
  <pre>
  TO:      <input type = "Text" name = "MailTo">
  FROM: <input type = "Text" name = "MailFrom">
  SUBJECT:   <input type = "Text" name = "Subject">
  <hr>
  MESSAGE BODY:
  <textarea name ="body" cols="40" rows="5" wrap="virtual"></textarea>
  </pre>
  <!--- establish required fields --->
  <input type = "hidden" name = "MailTo_required" value = "You must enter
a recipient">
  <input type = "hidden" name = "MailFrom_required" value = "You must
enter a sender">
  <input type = "hidden" name = "Subject_required" value = "You must enter
a subject">
  <input type = "hidden" name = "Body_required" value = "You must enter
some text">
  <p><input type = "Submit" name = "">
</form> --->

Comments