Customizing Email Content

Personalization is simple with MailerSend’s API. Simply add a structure for the appropriate variables and call them in the parameters. You can use both simple and advanced personalization.

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 subjecthtml, and text fields in your email.

An example of simple personalization could be: “Hi {$name}. Thank you for shopping with us all the way from **{$country}**!

Simple 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": "Simple Personalization",
      "html": "<p>Hi {$name}, Thank you for shopping with us all the way from {$country}.</p>",
      "variables": [
      {
        "to": "recipient@email.com",
        "substitutions": [
          {
            "var": "name",
            "value": "Recipient Name"
          }
          {
            "var": "country",
            "value": "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.

Note about variables:

  • They must start with a dollar sign
  • They must be surrounded by curly brackets { }
  • They may contain alphanumeric characters and underscores (_) but not hyphens: '-’
  • They must not start with a number or underscore
  • They are case sensitive, meaning that {$VAR} is different from {$var}

Example of combination:

SyntaxOutputDetails
{$test}valueDisplays a simple variable (no array or object).

Congratulations! You've now sent an email with simple personalization via MailerSend's API using cURL

Advanced 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": "Advanced 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:

SyntaxOutputDetails
{{var}}valueDisplay a simple variable (no array or object).
{{object.key}}object-valueDisplay the key value of an object.
{{number + number}}4A simple calculation of two simple variables (no array or object).

Congratulations! You've now sent an email with advanced 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.

What’s next?

Last Updated: