Customizing Email Content
Personalization is simple with MailerSend’s API. Simply add a structure for the appropriate variables and call them in the parameters.
In this guide, we'll walk you through the process of sending a personalized email using cURL calls. You can also use any of our SDKs.
What do I need?
- MailerSend account
- Add and verify at least one sending domain
- Generate an API token
- Ensure you have curl installed on your machine
When sending emails using the MailerSend API, you can input basic data for each recipient using variables in the {{variable}}
format. This allows you to personalize the subject
, html
, and text
fields in your email.
An example could be: “Hi*{{name}}
**. Thank you for shopping with us all the way from **{{country}}**!
*”
Personalization email
Here’s an example request using cURL
curl --request POST \
--url https://api.mailersend.com/v1/email \
--header 'Authorization: Bearer API_KEY_HERE' \
--header 'content-type: application/json' \
--data '{
"to": [
{
"email": "recipient@email.com"
}
],
"from": {
"email": "your@email.com"
},
"subject": "Personalization",
"html": "<p>Hi {{name|default('there')}}, Thank you for shopping with us all the way from {{country}}.</p>",
"personalization": [
{
"email": "test@mailersend.com",
"data": {
"name": "Recipient name",
"country": "Recipient Country"
}
]
}
- Copy and paste the cURL command into your terminal
- Replace
API_KEY_HERE
with your actual MailerSend API key and customize the other fields to match your needs - Finally, hit the enter key to execute the command.
Notes about variables:
- They must be surrounded by double curly brackets
{{var}}
- They may contain alphanumeric characters and underscores (_)
- They must not start with a number or underscore
- They 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). |
Congratulations! You've now sent an email with personalization via MailerSend's API using cURL.
We're excited to have you on board and look forward to helping you integrate our service seamlessly into your application. If you have any questions or encounter any issues, don't hesitate to contact our support team for assistance.