Skip to content
Info

The following adheres to Send API v3.0

Use template language

Mailjet Send API allow to leverage template language in your transactional messages.

The Mailjet Template Language include fonctionality for :

  • variable substitution
  • conditions
  • loops
  • and a lot more...
Info

The Mj-TemplateLanguage property in the payload provided to Send API is optional but if you want to have the templating language interpreted, it will be mandatory and must have a true value.

Example

# This call sends an email to the given recipient with vars and custom vars.
curl -s \
	-X POST \
	--user "$MJ_APIKEY_PUBLIC:$MJ_APIKEY_PRIVATE" \
	https://api.mailjet.com/v3/send \
	-H 'Content-Type: application/json' \
	-d '{
		"FromEmail":"pilot@mailjet.com",
		"FromName":"Mailjet Pilot",
		"Subject":"Your email flight plan!",
		"Mj-TemplateLanguage":true,
		"Text-part":"Dear passenger, welcome to Mailjet! On this {{var:day:\"monday\"}}, may the delivery force be with you! {{var:personalmessage:\"\"}}",
		"Html-part":"<h3>Dear passenger, welcome to <a href=\"https://www.mailjet.com/\">Mailjet</a>!<br /> On this {{var:day:\"monday\"}}, may the delivery force be with you! {{var:personalmessage:\"\"}}",
		"Vars":{
				"day": "Monday"
		},
		"Recipients":[
				{
						"Email": "passenger1@mailjet.com",
						"Name": "passenger 1",
						"Vars": {
								"day": "Tuesday",
								"personalmessage": "Happy birthday!"
						}
				},
				{
						"Email": "passenger2@mailjet.com",
						"Name": "passenger 2"
				}
		]
	}'