Additional features
Personalization
MailerSend's Personalization feature allows you to personalize email messages by generating dynamic content for each recipient when sending emails using the Email endpoint.
- Personalization only compiles the template if
personalizationdata is passed via Email API - Personalization is available for
subject,htmlandtextfields - It is cached server-side, but the hash is calculated based on content so it will reset with every change
A limited version of the Twig v3.x templating engine is used as a template language.
Template language
Example of personalization passed to Email API:
{
"personalization": [
{
"email": "test@mailersend.com",
"data": {
"var": "value",
"boolean": true,
"object": {
"key" : "object-value"
},
"number": 2,
"array": [
1,
2,
3
]
}
}
]
}
Variables
Variables are used to print basic data. The variable should look like {{var}}. It starts with double curly brackets {{, followed by the variable name and is closed with double curly brackets }}.
Note
Variables are available in subject, html and text fields.
General rules:
- Must be surrounded by double curly brackets
{{var}} - May contain alphanumeric characters and underscores (_)
- Must not start with a number or underscore
- Are case sensitive, meaning that
{{VAR}}is different from{{var}}
Examples of combinations:
| Syntax | Output | Details |
|---|---|---|
{{var}} | value | Display a simple variable (no array or object). |
{{object.key}} | object-value | Display the key value of an object. |
{{number + number}} | 4 | A simple calculation of two simple variables (no array or object). |
Conditional statement
A conditional statement (i.e. if/elseif/else) appears inside {% %} block. A conditional block always starts with the if keyword followed by the statement that is being tested, and ends with the endif keyword.
Note
Conditional statements are only available in html and text fields. Additional filters are also available in: escape, default, length, lower, upper and keys.
Example:
{% if boolean == true %}
Available
{% elseif number > 0 %}
Only {{number}} left!
{% else %}
Sold-out!
{% endif %}
Output:
Available
Foreach
A collection of data (an array) can be printed by looping through all the items in this collection. A loop should appear inside the {% %} block. A loop block always starts with the for keyword, and ends with the endfor keyword.
Note
Foreach is only available in html and text fields. Additional filters are also available in: escape, length, lower, upper and keys.
Example:
{% if array|length > 0 %}
<ul>
{% for value in array %}
<li>{{value}}</li>
{% endfor %}
</ul>
{% endif %}
Output:
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
</ul>
More details about iterating over keys, getting loop info, etc. can be found here.
Email Survey Templates
Using our drag-and-drop email builder, you may create email templates with a survey block to ask questions and reviews to your recipients. When your recipient receives an email with a survey, they can preview the email and answer your survey questions. Then the responses are sent to your webhook if available.
When a recipient answers all available survey questions the responses are immediately sent to your webhook(if available). However, when a recipient doesn't completely answer all available questions, after an idle time of 30 minutes, the responses would be sent.
Rules and steps for sending an email with a survey include:
- You cannot use the following variables
{{url}},{{survey}},{{survey_last_question}}, as they are reserved. - You must enable
content_trackingon your domain by selecting your domain and enabling the setting under tracking details. Content tracking is a feature available on Starter plans and above. - Add a webhook with the
activity.survey_submittedevent to receive the survey answers. - You can also include the
activity.survey_openedevent in your webhook to know when a recipient has opened an email containing a survey at least once.
Payloads
Example of activity.survey_submitted data sent to your webhook:
{
"type": "activity.survey_submitted",
"created_at": "2025-08-06T00:20:36.589903Z",
"data": {
"id": "68929fd47f916891ef12eba9",
"domain_id": "7nxe3yjmeq28vp0k",
"message_id": "68929fd402fd7079a02cf858",
"email_id": "68929fd47f916891ef12eba9",
"type": "survey_submitted",
"subject": "Test email",
"from": "test@domain.com",
"tags": [
"test2",
"test3"
],
"meta": {
"surveys": [
{
"question_id": 1,
"survey_id": 1,
"answer": "test",
"is_last_question": true
}
]
}
}
}