Send Email Transactional Messages Through Direct Send API
This Page
All Documentation
Use Direct Send APIs to preview and send transactional email to one or more recipients. The email comes from the published Salesforce CMS content that’s linked to the send definition. Personalize it with values that you pass in the request, and override parts of it or add attachments for each recipient.
Prerequisites
An access token that has the sfap_api scope. The token’s Run As user must have permission to create send definitions. See Connect to Direct Send APIs.
API version 68.0 or later for the send definition request.
A sender address on a domain that’s authorized for email sending in your org.
Published email content in Salesforce CMS, of type sfdc_cms__email, and its ContentKey. For content-variable personalization, supply values under attributes.$content that match the published content’s schema.
If you already have a send definition ID, skip to step 2.
Step 1: Create an Email Send Definition
Create the send definition on your org’s My Domain host. The sender is the fromAddress.
YOUR_AUTHORIZED_DOMAIN: A domain that’s authorized for email sending in your org.
YOUR_EMAIL_CONTENT_KEY: The ContentKey of the published email content.
YOUR_SUBSCRIPTION_NAME: The name of the communication subscription. Whether Email requires one depends on your org’s consent settings. When a promotional subscription is required and you omit it, the API uses the Marketing subscription, which must be configured in your org.
Use role-based sender addresses, such as noreply@, support@, or orders@. Email send definition names must be unique in your org.
The response contains the sendDefinitionId. Save it for the next steps.
You can also pass these optional fields.
Field
Description
fromName
The sender’s display name.
replyToAddress
The reply-to email address.
replyToName
The reply-to display name.
messagePurpose
PROMOTIONAL or TRANSACTIONAL. Required if you don’t pass managedContentKey, or if the content has no purpose. If the content has a purpose, this value must match it. See Message Purpose.
openTrackingEnabled
Indicates whether email opens are tracked. Email is the only channel with open tracking. See Tracking.
clickTrackingEnabled
Indicates whether link clicks are tracked.
dataSpaceName
The developer name of a data space. If you omit it, the API uses the default data space.
Preview renders the email without sending it. Use it to test combinations of content and data. Preview requires individualId and attributes. It doesn’t require to, because no email is delivered. A complete email needs a subject and at least an HTML body or a plain-text body. These can come from the linked CMS content. If you supply the complete content inline, include subject and at least one of body or text.
Preview and send go to api.salesforce.com, not to your My Domain host. If you call the same path on your My Domain host, the request returns a 404 page that says URL No Longer Exists.
Replace YOUR_SEND_DEFINITION_ID with the ID from step 1. For a test org, use https://test.api.salesforce.com/automation/actions360 as the base URL.
A 200 response contains the rendered content under response.
1{2 "response": {3 "subject": "Welcome to Acme Corp, Alice!",4 "body": "<html>...rendered HTML...</html>",5 "text": "Welcome to Acme Corp, Alice! ...",6 "preheader": "Your account is ready"7}8}
Check that the subject, HTML body, plain text, and preheader look the way you expect. If the body is empty, check that the CMS content is published and that the send definition links the email content that you intended.
Step 3: Send to One Recipient
Use the same endpoint without /preview. This request delivers the email, so set to to an inbox that you control.
A 200 response means that the request was processed. Check the recipient’s status, SUCCESS or FAIL, to find out whether the email was accepted for delivery. Acceptance doesn’t confirm delivery. See Handle Responses, Errors, and Retries in Direct Send API.
Step 4: Send to Multiple Recipients
To send one email to many addresses, post to the /bulk endpoint. Pass a recipients array and an optional batch-level requestId. Each recipient can have its own locale, overrides, and attachments.
Pass the personalization values that the published content expects. Email supports three personalization models. Use the model that your content was built for, and keep the namespaces separate.
Model
When to Use It
How to Pass Values
Content variables (recommended)
The content declares its variables in contentBody["sfdc_cms:schema"] and reads them from $content.
Under attributes.$content, as in step 3.
Apex-backed content
The content uses an Apex data provider.
Under the expression key that the provider configures, such as "attributes": {"ApexClassName": {"field1": "value1"}}.
Free-form variables
The content uses free-form variables, such as $firstName.
Directly under attributes, such as "attributes": {"firstName": "Alice"}.
For content variables, the $content key is case-sensitive, and the property names and casing must match the schema. Supply every property that the schema requires. In raw HTML email content, the Handlebars lookup looks like {{fallback (get (get @root "$content") "firstName") "-"}}.
The content schema doesn’t describe or validate free-form values, and a free-form value doesn’t fill a $content variable.
Other system or channel attributes, such as $link, can sit next to $content in attributes.
Override Parts of the Email
These optional fields go on the recipient object, next to attributes, not inside it. In a bulk send, they can differ for each recipient.
Field
Description
subject
Overrides the subject template.
body
Overrides the HTML body template.
text
Overrides the plain-text template.
from
Overrides the from address.
replyTo
Overrides the reply-to address.
cc
An array of CC email addresses.
bcc
An array of BCC email addresses, such as ["audit@example.com"]. Other recipients don’t see BCC addresses.
ttlSeconds
The maximum lifetime of the email, from 1 through 86,400 seconds (24 hours). If you omit it, the service’s default expiration applies.
You supply attachments when you send. The send definition doesn’t need any attachment setup, and each recipient can have different files. Each attachment has four fields.
fileLocationType: Set to "base64".
fileLocation: The file’s bytes as a Base64 string, with no line breaks and no data:...;base64, prefix.
fileName: The file name, such as invoice.pdf. The extension must match the file format.
contentType: The file’s MIME type. The API doesn’t infer it from fileName, so always set it.