Skip to content
Last updated

Create a template

Email templates are prewritten / preformatted emails, which are used to quickly send messages to your recipients. This helps you save time when needing to reuse content - instead of adding the email content every time, you can just reference the template ID.

You can create a template using our Email Editor. To create a template via the API, use POST /template.

Example

curl -s \
	-X POST \
	--user "$MJ_APIKEY_PUBLIC:$MJ_APIKEY_PRIVATE" \
	https://api.mailjet.com/v3/REST/template \
	-H 'Content-Type: application/json' \
	-d '{
      "Author":"John Doe",
      "Categories":"array",
      "Copyright":"Mailjet",
      "Description":"Used to send out promo codes.",
      "EditMode":"1",
      "IsStarred":"false",
      "IsTextPartGenerationEnabled":"true",
      "Locale":"en_US",
      "Name":"Promo Codes",
      "OwnerType":"user",
      "Presets":"string",
      "Purposes":"array"
	}'

To add the email content, use POST /template/{template_ID}/detailcontent. Keep in mind that the POST request will reset the values of all properties not specified in the payload to null. If you have already set a value to a property (e.g. Html-part) and want to keep it while setting the value of another (e.g. Text-part), use a PUT request instead.

curl -s \
	-X POST \
	--user "$MJ_APIKEY_PUBLIC:$MJ_APIKEY_PRIVATE" \
	https://api.mailjet.com/v3/REST/template/$template_ID/detailcontent \
	-H 'Content-Type: application/json' \
	-d '{
      "Headers":"",
      "Html-part":"<h3>Dear passenger, welcome to Mailjet!</h3><br />May the delivery force be with you!",
      "MJMLContent":"",
      "Text-part":"Dear passenger, welcome to Mailjet! May the delivery force be with you!"
	}'

Use Headers to specify your sender and/or reply-to addresses, as well as the Subject line of your email.

{
  "From": "\"Mailjet pilot\" <pilot@mailjet.com>",
  "Subject": "Welcome",
  "Reply-to": "copilot@mailjet.com"
}