Skip to content

Personalization

Content Formatting

Mailjet offers a templating language that allows you to personalize your transactional messages. It enables you to insert data in your text or HTML parts.

To do so, use {{DATA_TYPE:DATA_NAME}} where:

  • DATA_TYPE: var for Variables specified in the API call or data for contact data, which is already available in the Mailjet system

  • DATA_NAME: name of the data you want to insert

Info

NOTICE: The TemplateLanguage property should be set to true to force Send API to interpret the template language (X-MJ-TemplateLanguage in case you are using SMTP).

Visit our Transactional templating guide to learn about additional substitutions, modification functions and conditional statements you can use to personalize your messages.

User vars and custom vars

By using Variables in conjunction with the {{var:VAR_NAME}} or {{var:VAR_NAME:DEFAULT_VALUE}} , you can modify the content of your email with variables, pushed in your Send API call.

DEFAULT_VALUEis the default value that will be used, if the variable is not defined in the API call.

Example

# This call sends a message to a recipient with global personalisation.
curl -s \
	-X POST \
	--user "$MJ_APIKEY_PUBLIC:$MJ_APIKEY_PRIVATE" \
	https://api.mailjet.com/v3.1/send \
	-H 'Content-Type: application/json' \
	-d '{
		"Messages":[
				{
						"From": {
								"Email": "pilot@mailjet.com",
								"Name": "Mailjet Pilot"
						},
						"To": [
								{
										"Email": "passenger1@mailjet.com",
										"Name": "passenger 1"
								}
						],
						"Variables": {
								"day": "Monday"
						},
						"TemplateLanguage": true,
						"Subject": "Your email flight plan!",
						"TextPart": "Dear passenger, welcome to Mailjet! On this {{var:day}}, may the delivery force be with you!",
						"HTMLPart": "<h3>Dear passenger, welcome to <a href=\"https://www.mailjet.com/\">Mailjet</a>!</h3><br />On this {{var:day}}, may the delivery force be with you!"
				}
		]
	}'

Use contact properties

If the contact you are sending an email to is already existing in the Mailjet system with some contact data, you can leverage this information to personalize your email.

Use {{data:METADATA_NAME}} or {{data:METADATA_NAME:DEFAULT_VALUE}} to insert data in your content.

DEFAULT_VALUE is the default value that will be used if no data is found.

Refer to the Personalization section for more information on how to add contact properties.

# This call sends a message to the a recipient with contact property personalisation.
curl -s \
	-X POST \
	--user "$MJ_APIKEY_PUBLIC:$MJ_APIKEY_PRIVATE" \
	https://api.mailjet.com/v3.1/send \
	-H 'Content-Type: application/json' \
	-d '{
		"Messages":[
				{
						"From": {
								"Email": "pilot@mailjet.com",
								"Name": "Mailjet Pilot"
						},
						"To": [
								{
										"Email": "passenger1@mailjet.com",
										"Name": "passenger 1"
								}
						],
						"TemplateLanguage": true,
						"Subject": "Your email flight plan!",
						"TextPart": "Dear {{data:firstname:\"passenger\"}}, welcome to Mailjet! May the delivery force be with you!",
						"HTMLPart": "<h3>Dear {{data:firstname:\"passenger\"}}, welcome to <a href=\"https://www.mailjet.com/\">Mailjet</a>!<br /> May the delivery force be with you!"
				}
		]
	}'