The Send API v3.1 sends a collection of messages, added in JSON array, called Messages. The input payload must start with it. The mandatory properties for any message element are:
From: JSON object, containing 2 properties:NameandEmailaddress of a previously validated and active sender. Including theNameproperty in the JSON is optional. This property is not mandatory in case you useTemplateIDand you specified aFromaddress for the template. Format : {"Email":"value","Name":"value"}.To: array of JSON objects describing each recipient. Format : [{"Email":"value","Name":"value"},...]. Here again the inclusion of theNameproperty in the JSON is optional. The same is also valid for theCcandBccobjects, who have the same structure.
One of the following content parts is also mandatory :
TextPartand/orHtmlPart: content of the message, sent in Text and/or HTML format. At least one of these content types needs to be specified. When the HTML part is the only part provided, Mailjet will not generate a Text-part from the HTML version. The property can't be set when you useTemplateID.TemplateID: an ID for a template that is previously created and stored in Mailjet's system. It is mandatory whenFromandTextPartand/orHtmlPartare not provided. Visit the Use a Template section for more information.
Important: The recipients listed in To will receive a common message, showing every other recipient and carbon copy (CC) recipients. If you do not wish the recipients to see each other, you have to create multiple messages in the Messages array.
# This call sends a message to one recipient.
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"
}
],
"Subject": "Your email flight plan!",
"TextPart": "Dear passenger 1, welcome to Mailjet! May the delivery force be with you!",
"HTMLPart": "<h3>Dear passenger 1, welcome to <a href=\"https://www.mailjet.com/\">Mailjet</a>!</h3><br />May the delivery force be with you!"
}
]
}'
{
"Messages": [
{
"Status": "success",
"To": [
{
"Email": "passenger1@mailjet.com",
"MessageUUID": "123",
"MessageID": 456,
"MessageHref": "https://api.mailjet.com/v3/message/456"
}
]
}
]
}Send API will send a response containing an array of Messages. Each instance of the message object will include the Status and the list of message UUIDs for each recipient in To, Cc and Bcc.
MessageUUID is the internal Mailjet ID of your message.
MessageID is the unique ID of the message (legacy format). You will be able to use this id to get more information about your message.
MessageHref is a URL, pointing to the API URL, where the message metadata can be retrieved. It is made of the API Base URL, the message resource path and the message ID (not UUID).
NOTICE: If you send an email to a contact, which is not registered in Mailjet, the system will automatically create and save it. Keep this in mind if you intend to use this email address later (for example to add it to a contact list), as it will already exist in Mailjet and there's no need to create it again.
# This call sends a message to one recipient.
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"
},
{
"Email": "passenger2@mailjet.com",
"Name": "passenger 2"
}
],
"Cc": [
{
"Email": "copilot@mailjet.com",
"Name": "Copilot"
}
],
"Bcc": [
{
"Email": "air-traffic-control@mailjet.com",
"Name": "Air traffic control"
}
],
"Subject": "Your email flight plan!",
"TextPart": "Dear passenger 1, welcome to Mailjet! May the delivery force be with you!",
"HTMLPart": "<h3>Dear passenger 1, welcome to <a href=\"https://www.mailjet.com/\">Mailjet</a>!</h3><br />May the delivery force be with you!"
}
]
}'{
"Messages": [
{
"Status": "success",
"To": [
{
"Email": "passenger1@mailjet.com",
"MessageUUID": "123",
"MessageID": 456,
"MessageHref": "https://api.mailjet.com/v3/message/456"
},
{
"Email": "passenger2@mailjet.com",
"MessageUUID": "124",
"MessageID": 457,
"MessageHref": "https://api.mailjet.com/v3/message/457"
}
],
"Cc": [
{
"Email": "copilot@mailjet.com",
"MessageUUID": "125",
"MessageID": 458,
"MessageHref": "https://api.mailjet.com/v3/message/458"
}
],
"Bcc": [
{
"Email": "air-traffic-control@mailjet.com",
"MessageUUID": "126",
"MessageID": 459,
"MessageHref": "https://api.mailjet.com/v3/message/459"
}
]
}
]
}