Add a variable to a transactional email template
With Sitecore Send's transactional campaigns, you have a variety of options for adding images, files, and other dynamic content, such as a product name.
This topic is for developers or advanced users and requires knowledge of the API.
Dynamically add an image from a public URL
You can add a image that you've stored in the cloud to the text item of a transactional campaign email. For example, a screenshot of a receipt.
To add the image, you'll need to add the image URL to the API and add the image variable to the campaign:
-
In the API payload, format your JSON like this example:
RequestResponse"Personalizations": [ { "To": [ { "Email": "[email protected]", "Name": "John Doe" } ], "Substitutions": [ { "product": "value1", "image": "https://urlexample.com" } ] } ]
-
In Sitecore Send, in the transactional campaign editor:
-
Add a text item and place the cursor where you want to add the image.
-
Enter the image variable using the format
#image#
or{{image}}
.
-
The image will appear in the body text of the transactional campaign email when you send it.
Embed a file as an attachment through the API
From the API, you can add a file of any format, including PDF, TXT, or an image, as an attachment to your transactional campaign email.
To add the file:
-
In the the API payload, enter the file in the
attachments
object as a key-value pair, following the format"Filename": "filename.extension"
:RequestResponse"attachments": [ { "content": "iVBORw0KGgoAAAAAfcAYDAAAAADQB4zBAAAAAAB9wBgMAAAAANAHjMEAAAAAAH3AGAwAAAAA0AeMwQAAAAAAfcAYDAAAAADQB4zBAAAAAAB9wBgMAAAAANAHjMEAAAAAAH3AGAwAAAAA0AeMwQAAAAAAPe+T+J/nnNIPnRqhbwAAAABJRU5ErkJggg==", "Type" : "application/pdf", "FileName" : "example.pdf", "Disposition" : "attachment", "ContentId" : "exampleattachment" } ]
The file will be added as an attachment to the transactional campaign email when you send it.
Add an inline image
You can add a inline image in the content of a transactional campaign email. For example, screenshot of a receipt.
For this, you need a Base64-encoded image.
To add the inline image, you'll need to add the Base64 code in the API and enter an API reference to the image in the campaign email:
-
In the API payload, enter the
attachments
parameter using this format, where the value of"content"
is the Base64-encoded image:RequestResponse"attachments": [ { "content": "iVBORw0KGgoAAAAAfcAYDAAAAADQB4zBAAAAAAB9wBgMAAAAANAHjMEAAAAAAH3AGAwAAAAA0AeMwQAAAAAAfcAYDAAAAADQB4zBAAAAAAB9wBgMAAAAANAHjMEAAAAAAH3AGAwAAAAA0AeMwQAAAAAAPe+T+J/nnNIPnRqhbwAAAABJRU5ErkJggg==", "type": "image/PNG", "filename": "imageexample.png", "disposition": "inline", "contentId": "image-a" } ]
-
In Sitecore Send, in the transactional campaign editor:
-
Add a text item and place the cursor where you want to add the inline image.
-
Enter the text
cid:
, followed by thecontentId
(cid
) value from theattachment
parameter in the API. For example,#cid:image-a#
.
-
The image variable will be replaced by the actual image in the transactional campaign email when you send it.
Add dynamic text
You can add dynamic text in the transactional campaign email. For example, a product variable.
To add the dynamic text, you'll need to define the variable in the API and add the variable in the campaign email:
When the email is sent, the dynamic text variable is replaced by the actual image.
-
In the API payload, define the value of the
"product"
variable in thePersonalization
parameter using this format:RequestResponse"Personalizations": [ { "To": [ { "Email": "[email protected]", "Name": "John Doe" } ], "Substitutions": [ { "product": "value1", "image": "https://urlexample.com" } ] } ]
-
In Sitecore Send, in the transactional campaign editor:
-
Add a text item and place the cursor where you want to add the dynamic text.
-
Enter a word surrounded by hashtags using the format #product# or {{product}}, corresponding to the
"product"
parameter in the API payload.
-