Sends a transactional email to a single contact. A transactional email ignores all contact opt out preferences and should only be used for transactional communication.
Personalize using custom fields
Optionally include a JSON body with properties used to personalize the email.
{
"subject":"My new email subject", // optional to set a subject
"from":"[email protected]", // optional set a from address
"confirmation_url":"https://example.com", // optional set a profile field
"confirmation_code":"confirmation-38474" // optional set a profile field
}
These fields are then accessible in the email.
The following fields are reserved fields:
subject
- (required) set an alternate subject for the email.from
- (required) set an alternate from address for the email.body
- (required) set the body of the email.preheader
- set an alternate preheader for the email.plaintext
- set an alternate plaintext for the email.cc
- carbon copy recipients. Must be in standard email format. Multiple addresses should be separated with a semi-colon.bcc
- blind carbon copy recipient. Must be in standard email format. Multiple addresses should be separated with a semi-colon.reply-to
- set the reply-to header of the email. Must be in standard email format. Only a single address is allowed.attachments
- include one or more attachments.
Personalization example
Hello, your confirmation code is{{profile.confirmation_code}}
.
It's also possible to send a subject or from with a personalization token, for example:
{
"subject":"Your id is {{@profile.custom_id}}"
}
When the email is sent if the contact has a personalization field of "custom_id
" it will automatically be inserted.
Including Attachments
DailyStory supports email attachments. However, we generally discourage the use and recommend using URLs to resources instead. To enable email attachments for your account, please contact our support team.
While attachments for marketing emails are disabled by default. Attachments for transactional emails using the transactional email API are supported.
Adding attachments to a transactional email
Attachments are sent as part of the JSON message object using the field attachments
. However, for various reasons there are multiple steps to properly serialize the attachment information.
For the purpose of this example we'll use a file called helloworld.txt with the value "Hello world!".
Convert file to base 64 encoded byte array
In your code, first convert your file content in to a byte array. Then encode it as a base 64 encoded string. For example:
SABlAGwAbABvACAAdwBvAHIAbABkACEA
Is the base 64 encoded byte array for the contents of the helloworld.txt file.
Build a JSON array of key/value pairs
Next, create list of JSON objects of key/value pairs where the key in the name of the file and the value is the base 64 encoded byte array:
{"helloworld.txt":"SABlAGwAbABvACAAdwBvAHIAbABkACEA"}
For example, to include a second copy of this file:
{"helloworld.txt":"SABlAGwAbABvACAAdwBvAHIAbABkACEA"},{"world.txt":"SABlAGwAbABvACAAdwBvAHIAbABkACEA"}
Base 64 encode the string of JSON
For example, below is the base 64 encoded version of the helloworld.txt single attachment example:
eyJoZWxsb3dvcmxkLnR4dCI6IlNBQmxBR3dBYkFCdkFDQUFkd0J2QUhJQWJBQmtBQ0VBIn0=
Finally send the email
A possible email payload for the API could look like:
{
"from":"[email protected]",
"subject":"Example email with an attachment",
"body":"The body of my email. See the attachment below.",
"attachments": "eyJoZWxsb3dvcmxkLnR4dCI6IlNBQmxBR3dBYkFCdkFDQUFkd0J2QUhJQWJBQmtBQ0VBIn0K"
}