Using template with Send API

Send API, Mailjet Transactional API, allow you to leverage the power of the template language.

The templates and template language can be used in multiple ways with Send API:

  • posting on /send resource with message content as TextPart or HtmlPart
  • saving the content of the message with the /template resource and using it on demand with the TemplateID property of Send API.
  • using templates you created through the Passport User Interface.

Note

In order to have the template language interpreted, you must provide TemplateLanguage property in the payload to the Send API and set it to true.

Refer to the Send API guide for more information.

Send a message, containing template language

You can simply pass in the payload of the call to Send API a text version (TextPart property) and/or an Html version (HtmlPart property) containing template language.

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": "passenger@mailjet.com",
					"Name": "passenger"
					}
				],
				"Subject": "Your email flight plan!",
				"TemplateLanguage": true,
				"TextPart": "Dear {{data:firstname:\"passenger\"}}, welcome to Mailjet! ",
				"HTMLPart": "

Dear {{data:firstname:\"passenger\"}}, welcome to Mailjet!


" } ] }'
<?php
/*
This calls sends a message based on a template.
*/
require 'vendor/autoload.php';
use \Mailjet\Resources;
$mj = new \Mailjet\Client(getenv('MJ_APIKEY_PUBLIC'), getenv('MJ_APIKEY_PRIVATE'),true,['version' => 'v3.1']);
$body = [
    'Messages' => [
        [
            'From' => [
                'Email' => "pilot@mailjet.com",
                'Name' => "Mailjet Pilot"
            ],
            'To' => [
                [
                    'Email' => "passenger@mailjet.com",
                    'Name' => "passenger"
                ]
            ],
            'Subject' => "Your email flight plan!",
            'TemplateLanguage' => true,
            'TextPart' => "Dear {{data:firstname:\"passenger\"}}, welcome to Mailjet! ",
            'HTMLPart' => "

Dear {{data:firstname:\"passenger\"}}, welcome to Mailjet!


" ] ] ]; $response = $mj->post(Resources::$Email, ['body' => $body]); $response->success() && var_dump($response->getData()); ?>
/**
 *
 * This calls sends a message based on a template.
 *
 */
const mailjet = require ('node-mailjet')
	.connect(process.env.MJ_APIKEY_PUBLIC, process.env.MJ_APIKEY_PRIVATE)
const request = mailjet
	.post("send", {'version': 'v3.1'})
	.request({
		"Messages":[
			{
				"From": {
					"Email": "pilot@mailjet.com",
					"Name": "Mailjet Pilot"
				},
				"To": [
					{
					"Email": "passenger@mailjet.com",
					"Name": "passenger"
					}
				],
				"Subject": "Your email flight plan!",
				"TemplateLanguage": true,
				"TextPart": "Dear {{data:firstname:\"passenger\"}}, welcome to Mailjet! ",
				"HTMLPart": "

Dear {{data:firstname:\"passenger\"}}, welcome to Mailjet!


" } ] }) request .then((result) => { console.log(result.body) }) .catch((err) => { console.log(err.statusCode) })
# This calls sends a message based on a template.
require 'mailjet'
Mailjet.configure do |config|
  config.api_key = ENV['MJ_APIKEY_PUBLIC']
  config.secret_key = ENV['MJ_APIKEY_PRIVATE']  
  config.api_version = "v3.1"
end
variable = Mailjet::Send.create(messages: [{
    'From'=> {
        'Email'=> 'pilot@mailjet.com',
        'Name'=> 'Mailjet Pilot'
    },
    'To'=> [
        {
            'Email'=> 'passenger@mailjet.com',
            'Name'=> 'passenger'
        }
    ],
    'Subject'=> 'Your email flight plan!',
    'TemplateLanguage'=> true,
    'TextPart'=> 'Dear {{data:firstname:\'passenger\'}}, welcome to Mailjet! ',
    'HTMLPart'=> '

Dear {{data:firstname:\'passenger\'}}, welcome to Mailjet!


' }] ) p variable.attributes['Messages']
"""
This calls sends a message based on a template.
"""
from mailjet_rest import Client
import os
api_key = os.environ['MJ_APIKEY_PUBLIC']
api_secret = os.environ['MJ_APIKEY_PRIVATE']
mailjet = Client(auth=(api_key, api_secret), version='v3.1')
data = {
  'Messages': [
	{
		"From": {
			"Email": "pilot@mailjet.com",
			"Name": "Mailjet Pilot"
		},
		"To": [
			{
			"Email": "passenger@mailjet.com",
			"Name": "passenger"
			}
		],
		"Subject": "Your email flight plan!",
		"TemplateLanguage": True,
		"TextPart": "Dear {{data:firstname:\"passenger\"}}, welcome to Mailjet! ",
		"HTMLPart": "

Dear {{data:firstname:\"passenger\"}}, welcome to Mailjet!


" } ] } result = mailjet.send.create(data=data) print result.status_code print result.json()
package com.my.project;
import com.mailjet.client.errors.MailjetException;
import com.mailjet.client.errors.MailjetSocketTimeoutException;
import com.mailjet.client.MailjetClient;
import com.mailjet.client.MailjetRequest;
import com.mailjet.client.MailjetResponse;
import com.mailjet.client.ClientOptions;
import com.mailjet.client.resource.Emailv31;
import org.json.JSONArray;
import org.json.JSONObject;
public class MyClass {
    /**
     * This call sends a message to one recipient.
     */
    public static void main(String[] args) throws MailjetException, MailjetSocketTimeoutException {
      MailjetClient client;
      MailjetRequest request;
      MailjetResponse response;
      client = new MailjetClient(System.getenv("MJ_APIKEY_PUBLIC"), System.getenv("MJ_APIKEY_PRIVATE"), new ClientOptions("v3.1"));
      request = new MailjetRequest(Emailv31.resource)
			.property(Emailv31.MESSAGES, new JSONArray()
                .put(new JSONObject()
                    .put(Emailv31.Message.FROM, new JSONObject()
                        .put("Email", "pilot@mailjet.com")
                        .put("Name", "Mailjet Pilot"))
                    .put(Emailv31.Message.TO, new JSONArray()
                        .put(new JSONObject()
                            .put("Email", "passenger@mailjet.com")
                            .put("Name", "passenger")))
                    .put(Emailv31.Message.SUBJECT, "Your email flight plan!")
                    .put(Emailv31.Message.TEMPLATELANGUAGE, true)
                    .put(Emailv31.Message.TEXTPART, "Dear {{data:firstname:\"passenger\"}}, welcome to Mailjet! ")
                    .put(Emailv31.Message.HTMLPART, "

Dear {{data:firstname:\"passenger\"}}, welcome to Mailjet!


"))); response = client.post(request); System.out.println(response.getStatus()); System.out.println(response.getData()); } }
/*
This calls sends a message based on a template.
*/
package main
import (
	"fmt"
	"log"
	"os"
	mailjet "github.com/mailjet/mailjet-apiv3-go"
)
func main () {
	mailjetClient := NewMailjetClient(os.Getenv("MJ_APIKEY_PUBLIC"), os.Getenv("MJ_APIKEY_PRIVATE"))
	messagesInfo := []mailjet.InfoMessagesV31 {
      mailjet.InfoMessagesV31{
        From: &mailjet.RecipientV31{
          Email: "pilot@mailjet.com",
          Name: "Mailjet Pilot",
        },
        To: &mailjet.RecipientsV31{
          mailjet.RecipientV31 {
            Email: "passenger@mailjet.com",
            Name: "passenger",
          },
        },
        Subject: "Your email flight plan!",
        TemplateLanguage: true,
      TextPart: "Dear {{data:firstname:\"passenger\"}}, welcome to Mailjet! ",
      HTMLPart: "

Dear {{data:firstname:\"passenger\"}}, welcome to Mailjet!


", }, } messages := mailjet.MessagesV31{Info: messagesInfo } res, err := m.SendMailV31(&messages) if err != nil { log.Fatal(err) } fmt.Printf("Data: %+v\n", res) }
using Mailjet.Client;
using Mailjet.Client.Resources;
using System;
using Newtonsoft.Json.Linq;
namespace Mailjet.ConsoleApplication
{
   class Program
   {
      /// 
      /// This call sends a message to one recipient.
      /// 
      static void Main(string[] args)
      {
         RunAsync().Wait();
      }
      static async Task RunAsync()
      {
         MailjetClient client = new MailjetClient(Environment.GetEnvironmentVariable("MJ_APIKEY_PUBLIC"), Environment.GetEnvironmentVariable("MJ_APIKEY_PRIVATE"))
         {
            Version = ApiVersion.V3_1,
         };
         MailjetRequest request = new MailjetRequest
         {
            Resource = Send.Resource,
         }
            .Property(Send.Messages, new JArray {
                new JObject {
                 {"From", new JObject {
                  {"Email", "pilot@mailjet.com"},
                  {"Name", "Mailjet Pilot"}
                  }},
                 {"To", new JArray {
                  new JObject {
                   {"Email", "passenger@mailjet.com"},
                   {"Name", "passenger"}
                   }
                  }},
                 {"Subject", "Your email flight plan!"},
                 {"TemplateLanguage", true},
                 {"TextPart", "Dear {{data:firstname:\"passenger\"}}, welcome to Mailjet! "},
                 {"HTMLPart", "

Dear {{data:firstname:\"passenger\"}}, welcome to Mailjet!


"} } }); MailjetResponse response = await client.PostAsync(request); if (response.IsSuccessStatusCode) { Console.WriteLine(string.Format("Total: {0}, Count: {1}\n", response.GetTotal(), response.GetCount())); Console.WriteLine(response.GetData()); } else { Console.WriteLine(string.Format("StatusCode: {0}\n", response.StatusCode)); Console.WriteLine(string.Format("ErrorInfo: {0}\n", response.GetErrorInfo())); Console.WriteLine(response.GetData()); Console.WriteLine(string.Format("ErrorMessage: {0}\n", response.GetErrorMessage())); } } } }

Send a stored template

Use the TemplateID property in your Send API payload to specify the ID of the template you created.

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!"
			}
		]
	}'

<?php
/*
This call sends a message based on a template.
*/
require 'vendor/autoload.php';
use \Mailjet\Resources;
$mj = new \Mailjet\Client(getenv('MJ_APIKEY_PUBLIC'), getenv('MJ_APIKEY_PRIVATE'),true,['version' => 'v3.1']);
$body = [
    '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!"
        ]
    ]
];
$response = $mj->post(Resources::$Email, ['body' => $body]);
$response->success() && var_dump($response->getData());
?>

/**
 *
 * This calls sends a message based on a template.
 *
 */
const mailjet = require ('node-mailjet')
	.connect(process.env.MJ_APIKEY_PUBLIC, process.env.MJ_APIKEY_PRIVATE)
const request = mailjet
	.post("send", {'version': 'v3.1'})
	.request({
		"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!"
			}
		]
	})
request
	.then((result) => {
		console.log(result.body)
	})
	.catch((err) => {
		console.log(err.statusCode)
	})

# This calls sends a message based on a template.
require 'mailjet'
Mailjet.configure do |config|
  config.api_key = ENV['MJ_APIKEY_PUBLIC']
  config.secret_key = ENV['MJ_APIKEY_PRIVATE']  
  config.api_version = "v3.1"
end
variable = Mailjet::Send.create(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!'
}]
)
p variable.attributes['Messages']

"""
This calls sends a message based on a template.
"""
from mailjet_rest import Client
import os
api_key = os.environ['MJ_APIKEY_PUBLIC']
api_secret = os.environ['MJ_APIKEY_PRIVATE']
mailjet = Client(auth=(api_key, api_secret), version='v3.1')
data = {
  '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!"
	}
	]
}
result = mailjet.send.create(data=data)
print result.status_code
print result.json()

package com.my.project;
import com.mailjet.client.errors.MailjetException;
import com.mailjet.client.errors.MailjetSocketTimeoutException;
import com.mailjet.client.MailjetClient;
import com.mailjet.client.MailjetRequest;
import com.mailjet.client.MailjetResponse;
import com.mailjet.client.ClientOptions;
import com.mailjet.client.resource.Emailv31;
import org.json.JSONArray;
import org.json.JSONObject;
public class MyClass {
    /**
     * This call sends a message based on a template.
     */
    public static void main(String[] args) throws MailjetException, MailjetSocketTimeoutException {
      MailjetClient client;
      MailjetRequest request;
      MailjetResponse response;
      client = new MailjetClient(System.getenv("MJ_APIKEY_PUBLIC"), System.getenv("MJ_APIKEY_PRIVATE"), new ClientOptions("v3.1"));
      request = new MailjetRequest(Emailv31.resource)
			.property(Emailv31.MESSAGES, new JSONArray()
                .put(new JSONObject()
                    .put(Emailv31.Message.FROM, new JSONObject()
                        .put("Email", "pilot@mailjet.com")
                        .put("Name", "Mailjet Pilot"))
                    .put(Emailv31.Message.TO, new JSONArray()
                        .put(new JSONObject()
                            .put("Email", "passenger1@mailjet.com")
                            .put("Name", "passenger 1")))
                    .put(Emailv31.Message.TEMPLATEID, "1")
                    .put(Emailv31.Message.TEMPLATELANGUAGE, true)
                    .put(Emailv31.Message.SUBJECT, "Your email flight plan!")));
      response = client.post(request);
      System.out.println(response.getStatus());
      System.out.println(response.getData());
    }
}
/*
This calls sends a message based on a template.
*/
package main
import (
	"fmt"
	"log"
	"os"
	mailjet "github.com/mailjet/mailjet-apiv3-go"
)
func main () {
	mailjetClient := NewMailjetClient(os.Getenv("MJ_APIKEY_PUBLIC"), os.Getenv("MJ_APIKEY_PRIVATE"))
	messagesInfo := []mailjet.InfoMessagesV31 {
      mailjet.InfoMessagesV31{
        From: &mailjet.RecipientV31{
          Email: "pilot@mailjet.com",
          Name: "Mailjet Pilot",
        },
        To: &mailjet.RecipientsV31{
          mailjet.RecipientV31 {
            Email: "passenger1@mailjet.com",
            Name: "passenger 1",
          },
        },
        TemplateID: 1,
        TemplateLanguage: true,
        Subject: "Your email flight plan!",
      },
    }
	messages := mailjet.MessagesV31{Info: messagesInfo }
	res, err := m.SendMailV31(&messages)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("Data: %+v\n", res)
}
using Mailjet.Client;
using Mailjet.Client.Resources;
using System;
using Newtonsoft.Json.Linq;
namespace Mailjet.ConsoleApplication
{
   class Program
   {
      /// 
      /// This call sends a message based on a template.
      /// 
      static void Main(string[] args)
      {
         RunAsync().Wait();
      }
      static async Task RunAsync()
      {
         MailjetClient client = new MailjetClient(Environment.GetEnvironmentVariable("MJ_APIKEY_PUBLIC"), Environment.GetEnvironmentVariable("MJ_APIKEY_PRIVATE"))
         {
            Version = ApiVersion.V3_1,
         };
         MailjetRequest request = new MailjetRequest
         {
            Resource = Send.Resource,
         }
            .Property(Send.Messages, new JArray {
                new JObject {
                 {"From", new JObject {
                  {"Email", "pilot@mailjet.com"},
                  {"Name", "Mailjet Pilot"}
                  }},
                 {"To", new JArray {
                  new JObject {
                   {"Email", "passenger1@mailjet.com"},
                   {"Name", "passenger 1"}
                   }
                  }},
                 {"TemplateID", 1},
                 {"TemplateLanguage", true},
                 {"Subject", "Your email flight plan!"}
                 }
                });
         MailjetResponse response = await client.PostAsync(request);
         if (response.IsSuccessStatusCode)
         {
            Console.WriteLine(string.Format("Total: {0}, Count: {1}\n", response.GetTotal(), response.GetCount()));
            Console.WriteLine(response.GetData());
         }
         else
         {
            Console.WriteLine(string.Format("StatusCode: {0}\n", response.StatusCode));
            Console.WriteLine(string.Format("ErrorInfo: {0}\n", response.GetErrorInfo()));
            Console.WriteLine(response.GetData());
            Console.WriteLine(string.Format("ErrorMessage: {0}\n", response.GetErrorMessage()));
         }
      }
   }
}

Learn more about how to save and manage your templates on Mailjet in our Template API guide

Templates error management

Send API offers two payload properties to allow error management:

  • TemplateErrorReporting: Email Address where a message with the error description is sent to.
  • TemplateErrorDeliver: Determines if the message should - or not - be delivered to the recipient in case of an error, when processing the message's template language.

By default, when there is an error in the template, the message will not be delivered to the recipient and the message will have a `blocked' status in the Mailjet statistics.

If an error occurs when the template error reporting is enabled, a message from templating-language-error@mailjet.com with subject Error while evaluating Mailjet Templating language for message "original subject" will be delivered to the given error reporting address. It will contain the error message in the body and an attachment, containing the source of the original message (base64 encoded).

# This calls sends a message to a recipient and an template error email.
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!",
				"TemplateErrorDeliver": true,
				"TemplateErrorReporting": {
					"Email": "air-traffic-control@mailjet.com",
					"Name": "Air traffic control"
				}
			}
		]
	}'
<?
/*
This calls sends a message to a recipient and an template error email.
*/
require 'vendor/autoload.php';
use \Mailjet\Resources;
$mj = new \Mailjet\Client(getenv('MJ_APIKEY_PUBLIC'), getenv('MJ_APIKEY_PRIVATE'),true,['version' => 'v3.1']);
$body = [
    '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!",
            'TemplateErrorDeliver' => true,
            'TemplateErrorReporting' => [
                'Email' => "air-traffic-control@mailjet.com",
                'Name' => "Air traffic control"
            ]
        ]
    ]
];
$response = $mj->post(Resources::$Email, ['body' => $body]);
$response->success() && var_dump($response->getData());
?>

/**
 *
 * This calls sends a message to a recipient and an template error email.
 *
 */
const mailjet = require ('node-mailjet')
	.connect(process.env.MJ_APIKEY_PUBLIC, process.env.MJ_APIKEY_PRIVATE)
const request = mailjet
	.post("send", {'version': 'v3.1'})
	.request({
		"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!",
				"TemplateErrorDeliver": true,
				"TemplateErrorReporting": {
					"Email": "air-traffic-control@mailjet.com",
					"Name": "Air traffic control"
				}
			}
		]
	})
request
	.then((result) => {
		console.log(result.body)
	})
	.catch((err) => {
		console.log(err.statusCode)
	})
# This calls sends a message to a recipient and an template error email.
require 'mailjet'
Mailjet.configure do |config|
  config.api_key = ENV['MJ_APIKEY_PUBLIC']
  config.secret_key = ENV['MJ_APIKEY_PRIVATE']  
  config.api_version = "v3.1"
end
variable = Mailjet::Send.create(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!',
    'TemplateErrorDeliver'=> true,
    'TemplateErrorReporting'=> {
        'Email'=> 'air-traffic-control@mailjet.com',
        'Name'=> 'Air traffic control'
    }
}]
)
p variable.attributes['Messages']
"""
This calls sends a message to a recipient and an template error email.
"""
from mailjet_rest import Client
import os
api_key = os.environ['MJ_APIKEY_PUBLIC']
api_secret = os.environ['MJ_APIKEY_PRIVATE']
mailjet = Client(auth=(api_key, api_secret), version='v3.1')
data = {
  '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!",
			"TemplateErrorDeliver": true,
			"TemplateErrorReporting": {
				"Email": "air-traffic-control@mailjet.com",
				"Name": "Air traffic control"
			}
		}
	]
}
result = mailjet.send.create(data=data)
print result.status_code
print result.json()
package com.my.project;
import com.mailjet.client.errors.MailjetException;
import com.mailjet.client.errors.MailjetSocketTimeoutException;
import com.mailjet.client.MailjetClient;
import com.mailjet.client.MailjetRequest;
import com.mailjet.client.MailjetResponse;
import com.mailjet.client.ClientOptions;
import com.mailjet.client.resource.Emailv31;
import org.json.JSONArray;
import org.json.JSONObject;
public class MyClass {
    /**
     * This call sends a message to a recipient and a template error message.
     */
    public static void main(String[] args) throws MailjetException, MailjetSocketTimeoutException {
      MailjetClient client;
      MailjetRequest request;
      MailjetResponse response;
      client = new MailjetClient(System.getenv("MJ_APIKEY_PUBLIC"), System.getenv("MJ_APIKEY_PRIVATE"), new ClientOptions("v3.1"));
      request = new MailjetRequest(Emailv31.resource)
			.property(Emailv31.MESSAGES, new JSONArray()
                .put(new JSONObject()
                    .put(Emailv31.Message.FROM, new JSONObject()
                        .put("Email", "pilot@mailjet.com")
                        .put("Name", "Mailjet Pilot"))
                    .put(Emailv31.Message.TO, new JSONArray()
                        .put(new JSONObject()
                            .put("Email", "passenger1@mailjet.com")
                            .put("Name", "passenger 1")))
                    .put(Emailv31.Message.TEMPLATEID, "1")
                    .put(Emailv31.Message.TEMPLATELANGUAGE, true)
                    .put(Emailv31.Message.SUBJECT, "Your email flight plan!")
                    .put(Emailv31.Message.TEMPLATEERRORDELIVER, true)
                    .put(Emailv31.Message.TEMPLATEERRORREPORTING, new JSONObject()
                        .put("Email", "air-traffic-control@mailjet.com")
                        .put("Name", "Air traffic control"))));
      response = client.post(request);
      System.out.println(response.getStatus());
      System.out.println(response.getData());
    }
}
/*
This calls sends a message to a recipient and an template error email.
*/
package main
import (
	"fmt"
	"log"
	"os"
	mailjet "github.com/mailjet/mailjet-apiv3-go"
)
func main () {
	mailjetClient := NewMailjetClient(os.Getenv("MJ_APIKEY_PUBLIC"), os.Getenv("MJ_APIKEY_PRIVATE"))
	messagesInfo := []mailjet.InfoMessagesV31 {
      mailjet.InfoMessagesV31{
        From: &mailjet.RecipientV31{
          Email: "pilot@mailjet.com",
          Name: "Mailjet Pilot",
        },
        To: &mailjet.RecipientsV31{
          mailjet.RecipientV31 {
            Email: "passenger1@mailjet.com",
            Name: "passenger 1",
          },
        },
        TemplateID: 1,
        TemplateLanguage: true,
        Subject: "Your email flight plan!",
        TemplateErrorDeliver: true,
        TemplateErrorReporting: &mailjet.RecipientV31{
          Email: "air-traffic-control@mailjet.com",
          Name: "Air traffic control",
        },
      },
    }
	messages := mailjet.MessagesV31{Info: messagesInfo }
	res, err := m.SendMailV31(&messages)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("Data: %+v\n", res)
}
using Mailjet.Client;
using Mailjet.Client.Resources;
using System;
using Newtonsoft.Json.Linq;
namespace Mailjet.ConsoleApplication
{
   class Program
   {
      /// 
      /// This call sends a message to a recipient and a template error message.
      /// 
      static void Main(string[] args)
      {
         RunAsync().Wait();
      }
      static async Task RunAsync()
      {
         MailjetClient client = new MailjetClient(Environment.GetEnvironmentVariable("MJ_APIKEY_PUBLIC"), Environment.GetEnvironmentVariable("MJ_APIKEY_PRIVATE"))
         {
            Version = ApiVersion.V3_1,
         };
         MailjetRequest request = new MailjetRequest
         {
            Resource = Send.Resource,
         }
            .Property(Send.Messages, new JArray {
                new JObject {
                 {"From", new JObject {
                  {"Email", "pilot@mailjet.com"},
                  {"Name", "Mailjet Pilot"}
                  }},
                 {"To", new JArray {
                  new JObject {
                   {"Email", "passenger1@mailjet.com"},
                   {"Name", "passenger 1"}
                   }
                  }},
                 {"TemplateID", 1},
                 {"TemplateLanguage", true},
                 {"Subject", "Your email flight plan!"},
                 {"TemplateErrorDeliver", true},
                 {"TemplateErrorReporting", new JObject {
                  {"Email", "air-traffic-control@mailjet.com"},
                  {"Name", "Air traffic control"}
                  }}
                 }
                });
         MailjetResponse response = await client.PostAsync(request);
         if (response.IsSuccessStatusCode)
         {
            Console.WriteLine(string.Format("Total: {0}, Count: {1}\n", response.GetTotal(), response.GetCount()));
            Console.WriteLine(response.GetData());
         }
         else
         {
            Console.WriteLine(string.Format("StatusCode: {0}\n", response.StatusCode));
            Console.WriteLine(string.Format("ErrorInfo: {0}\n", response.GetErrorInfo()));
            Console.WriteLine(response.GetData());
            Console.WriteLine(string.Format("ErrorMessage: {0}\n", response.GetErrorMessage()));
         }
      }
   }
}

Common templating errors

  • expression parsing error ## Unknown identifier: var:day ## near ## {{var:day ## : This error indicates that the "day" variable is not defined in your Vars. It can be fixed by adding default value for the variable or making sure that you pass all the variables required by the template.
  • expression parsing error ## Unknown identifier: day ## near ## {{day ## : This error is similar to the previous one, except for the absence of namespace (var or data). It can indicates that you forgot to specify whether you want to use a Send API variable var:day or a contact property data:day. It can also indicate that you are trying to use a template variable that is neither define in a set function nor a loop statement.
  • not valid template ## near ## y}}</html> ## : This error occurs when the statement is not finished - missing {% endif %}
  • "var:day" is not an array value : This error is generally returned when you try to loop on a non-array value.