Dynamic e-mail content
Our API allows for inserting dynamic content into Email templates. This removes the need to create individual templates for particular recipients. All you have to do is create a single, universal template and use an API request to insert relevant data.
Email template
The options available with templates are:
Simple content insertion If you wish to use a predefined variable in a template and actually display its value:
<html>
<body>
Dear {{ name }},
We are pleased to inform you that …
</body>
</html>
Conditional instructions If you’re unsure whether the variable will always be set or would like to differentiate a part of the template depending on the variable’s value, use conditional instructions:
<html>
<body>
<div data-gb-custom-block data-tag="if">
Dear {{ name }},
<div data-gb-custom-block data-tag="elseif" data-0='male' data-1='male'></div>
Dear Sir,
<div data-gb-custom-block data-tag="elseif" data-0='female'></div>
Dear Madam,
<div data-gb-custom-block data-tag="else"></div>
Dear Sir/Madam,
</div>
We are pleased to inform you that …
</body>
</html>
Conditional instructions can contain the following operators: ==
, !=
, <
, <=
, >
, >=
Loops Our interface also allows for passing on datasets (product lists, for example) and dynamically generating content for each of its elements:
<p>List of available products:</p>
<ul>
<div data-gb-custom-block data-tag="for">
<li>
<b>{{product.name}}</b> - <span>{{product.color}}</span>
</li>
</div>
</ul>
Passing on data used in the dynamic content
Data can be passed on for both a specific recipient, using the vars
field, and an entire request using globalVars
field:
{
"subject": "Test email subject",
"smtpAccount": "1.test.smtp",
"from": {"email": "[email protected]", "name": "Sender Name"},
"globalVars": {
"products": [
{
"name": "skirt",
"id": 1,
"color": "green"
},
{
"name": "hoodie",
"id": 6,
"color": "red"
}
]
},
"to": [
{
"email": "[email protected]",
"messageId": "[email protected]",
"vars": {
"name": "Jane",
"sex": "female"
}
}
]
}