Menu

mail

Sends an email message through Salesforce using the user's Salesforce account. The child commands define most of the properties of the message, including the message body. As the email is sent through the user's Salesforce connection, the "From" field of the message is automatically set to the email address set in the user's Salesforce account, unless the attribute orgWideEmailAddressId is defined in which case an organization-wide alias may be used instead.

Mail & Mail2

Mail and its newer sibling command mail2 differ only in how they create the EmailMessage record should be the relatedTo attribute be defined. The commands' differences are as follows:

  • mail creates the EmailMessage record by itself. The record will not have the MessageIdentifier field defined. It may also require the orgWideEmailAddressData attribute defined for filling in certain field values if an organization-wide address is used. Any files attached to the email through child command attachment will be uploaded to Salesforce and linked to the created EmailMessage record.
  • mail2 lets Salesforce create the EmailMessage record. The record will have the MessageIdentifier field defined and filling in data of an organization-wide address into the record requires no additional attribute to be defined. Any files attached to the email through child command attachment will not appear as linked to the created EmailMessage record (only those attached with recordAttachment do).

 

Child commands

All the child commands set different properties of the generated email message.

  • to
    Required. Up to 100 recipients may be defined through these child commands, but at least one is required.
  • cc
    Optional. Up to 25 "CC" addresses may be specified through these child commands.
  • bcc
    Optional. Up to 25 "BCC" addresses may be specified through these child commands.
  • replyTo
    Optional. One child command of this kind may be present to set the "Reply-To" header.
  • textBody
    Optional. One child command of this kind may be present to set the message's plain text body.
  • htmlBody
    Optional. One child command of this kind may be present to set the message's HTML body.
  • attachment
    Optional. Any number of file attachments may be added through these child commands as long as the total file size doesn't exceed 10 MB. If the relatedTo attribute is defined and an EmailMessage created, these file attachments are uploaded to Salesforce and their corresponding ContentDocuments then linked to the EmailMessage.
  • recordAttachment
    Optional. Any number of record-based file attachments may be added through these child commands. Any ContentVersion records specified as attachments will also cause their ContentDocuments to be linked to the EmailMessage record generated if the relatedTo attribute is defined.  

Attributes

subject

Required
Value type
EL-evaluated
No String Yes
Defines the subject line of the email message.
senderName

Required
Value type
EL-evaluated
No String Yes
Defines the name of the message's sender. Do note that this only sets the name, not the "From" address.

This attribute may not be defined together with the orgWideEmailAddressId attribute - these two conflict and one of them has to remain undefined.

If not defined, the name set in the active user's Salesforce account appears as the sender. 
orgWideEmailAddressId


Required
Value type
EL-evaluated
No String Yes
Allows the email message's sender name and email address to be set to an organization-wide alias instead of the currently active user's name and email address. The expected value is the ID of an OrgWideEmailAddress record.

This attribute may not be defined together with the senderName attribute - these two conflict and one of them has to remain undefined.

If not defined, the name and email address set in the active user's Salesforce account appears as the sender information.
orgWideEmailAddressData

Required Value type EL-evaluated
No Map Yes
This attribute allows data of an organization-wide email alias to be provided instead of the data being automatically queried by this command. This data is required if the attributes orgWideEmailAddressId and relatedToare both defined, resulting in an EmailMessage record being created with the organization-wide alias' name and email address in it. The resolved value is expected to be a Map with the following contents:
  • An entry with the key "Address" and a String value that is the organization-wide email address (value of field "Address" in an OrgWideEmailAddress record).
  • An entry with the key "DisplayName" and a String value that is the name of the organization-wide alias (value of field "DisplayName" in an OrgWideEmailAddress record).

If not defined, this command will query data from the OrgWideEmailAddress record specified with orgWideEmailAddressId, if necessary. This will, however, fail if the active user doesn't have the administrative permission "View Setup and Configuration" in Salesforce.

relatedTo

Required Value type EL-evaluated
No String Yes
Allows the sending of the email message to be accompanied by a creation of an EmailMessage record that is linked to the record defined by this attribute. The resolved value should be the ID of a record of one of the following types:
  • Account
  • Asset
  • Campaign
  • Case
  • Contract
  • Opportunity
  • Order
  • Product
  • Solution
  • Any custom object type

Providing the ID of a record of any other type will cause Salesforce to return an error.

relatedToWhom

Required
Value type
EL-evaluated
No String Yes
If sending the email causes a Task record to be generated, this attribute defines the WhoId field of that email Task, which links it to a Contact, Lead or User. The resolved value is therefore expected to be the Id of a Contact, Lead or User record.  

If not defined, the generated Task will not be related to any Contact or such.
useSignature

Required
Value type
EL-evaluated
No Boolean Yes
Defines if the email-sending Salesforce user's email signature is included in the sent message.

If not defined, the value of "true" is used, causing the signature to be included.
inReplyTo

Required
Value type
EL-evaluated
No String Yes
Defines the In-Reply-To field of the sent email.

If not defined, this field is not included in the email.
references

Required
Value type
EL-evaluated
No String Yes
Defines the References field of the sent email.

If not defined, this field is not included in the email.

Examples

The mail command works together with all of its possible child commands in order to produce and send an email message. Note that you can also make use of the basic logic control commands, such as if and forEach, to dynamically alter the email properties.

<mail subject="Test mail">
  <to value="${teamLeader.emailAddress}">
  <forEach value="${teamMembers}" var="teamMember">
    <cc value="${teamMember.emailAddress}">
  <htmlBody value="${composedEmailBody}">
  <if test="${includeDoc}">
    <attachment value="${composedDoc}">

Comments

0 comments