Skip to content

Use a Template

Mailjet offers to store your transactional message templates on its platform. You can use these templates to avoid repeating the content of a transactional message at each Send API call.

You can either create the templates through our online drag and drop tool or through the /template resource.

You can also follow our Step by Step guide to create your first Passport template with templating language.

In the templates, you will be able to use simple personalization ([[data:property_name]] or [[var:variable_name]]) or advanced templating language ({{data:property_name}}, {{var:variable_name}}, conditional statements and loop statements).

In this sample, TemplateID will be the ID provided by Passport at the end of your designing process or the ID returned by the /template resource.

Info

The 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 a message based on a template.
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"
								}
						],
						"TemplateID": 1,
						"TemplateLanguage": true,
						"Subject": "Your email flight plan!"
				}
		]
	}'