# Send a basic email

The Send API v3.1 expects a JSON payload with a `Messages` array.
Each object in `Messages` represents one message to process.

## Required message properties

For each message, these properties are required:

- `From`: JSON object with `Email` and optionally `Name`.
The `Email` must be a previously [validated and active sender](https://app.mailjet.com/account/sender).
Format: `{ "Email": "value", "Name": "value" }`.
- `To`: array of recipient objects.
Each recipient requires `Email`, and `Name` is optional.
Format: `[{ "Email": "value", "Name": "value" }, ...]`.
The same object structure applies to `Cc` and `Bcc`.


You must also provide one of the following content options:

- `TextPart` and/or `HTMLPart`: message body in plain text and/or HTML.
At least one must be present when not using templates.
If only `HTMLPart` is provided, Mailjet does not generate a text part automatically.
- `TemplateID`: ID of a Mailjet template.
Use this when content comes from a stored template.
When template content is used, do not set `TextPart` or `HTMLPart`.


Info
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.

## Example: one recipient

This call sends a message to one recipient.

```shell cURL
curl -s \
	-X POST \
	--user "$MJ_APIKEY_PUBLIC:$MJ_APIKEY_PRIVATE" \
	https://api.mailjet.com/v3.1/send \
	-H 'Content-Type: application/json' \
	-d '{
      "SandboxMode":true,
      "Messages":[
        {
          "From":{
            "Email":"pilot@mailjet.com",
            "Name":"Your Mailjet Pilot"
          },
          "HTMLPart":"<h3>Dear passenger, welcome to Mailjet!</h3><br />May the delivery force be with you!",
          "Subject":"Your email flight plan!",
          "TextPart":"Dear passenger, welcome to Mailjet! May the delivery force be with you!",
          "To":[
            {
              "Email":"passenger@mailjet.com",
              "Name":"Passenger 1"
            }
          ]
        }
      ]
	}'
```

### API response

```
{
  "Messages": [
    {
      "Status": "success",
      "To": [
        {
          "Email": "passenger1@mailjet.com",
          "MessageUUID": "123",
          "MessageID": 456,
          "MessageHref": "https://api.mailjet.com/v3/message/456"
        }
      ]
    }
  ]
}
```

The response contains a `Messages` array.
Each message result includes `Status` and per-recipient tracking metadata for `To`, `Cc`, and `Bcc`.

`MessageUUID` is the internal Mailjet ID of your message.

`MessageID` is the unique ID of the message (legacy format), which you can use to fetch more message details.

`MessageHref` is the API URL where message metadata can be retrieved. It includes the API base URL, message resource path, and message ID (not UUID).

Info
Notice: If you send an email to a contact that does not exist yet in Mailjet, the contact is automatically created and saved.
If you plan to use that address later (for example in a contact list), there is no need to create it again.

## Example: multiple recipients with Cc and Bcc

cURL
```shell
# 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!"
				}
		]
	}'
```

PHP
```php
<?php
/*
This call sends a message to one recipient.
*/
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"
                ],
                [
                    '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!"
        ]
    ]
];
$response = $mj->post(Resources::$Email, ['body' => $body]);
$response->success() && var_dump($response->getData());
?>
```

Node.js
```javascript
/**
 *
 * This call sends a message to one recipient.
 *
 */
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"
								},
								{
										"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!"
				}
		]
	})
request
	.then((result) => {
		console.log(result.body)
	})
	.catch((err) => {
		console.log(err.statusCode)
	})
```

Ruby
```ruby
# This call sends a message to one recipient.
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'
        },
        {
            '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!'
}]
)
p variable.attributes['Messages']
```

Python
```python
"""
This call sends a message to one recipient.
"""
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"
								},
								{
										"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!"
				}
		]
}
result = mailjet.send.create(data=data)
print result.status_code
print result.json()
```

Java
```java
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", "passenger1@mailjet.com")
                            .put("Name", "passenger 1"))
                        .put(new JSONObject()
                            .put("Email", "passenger2@mailjet.com")
                            .put("Name", "passenger 2")))
                    .put(Emailv31.Message.CC, new JSONArray()
                        .put(new JSONObject()
                            .put("Email", "copilot@mailjet.com")
                            .put("Name", "Copilot")))
                    .put(Emailv31.Message.BCC, new JSONArray()
                        .put(new JSONObject()
                            .put("Email", "air-traffic-control@mailjet.com")
                            .put("Name", "Air traffic control")))
                    .put(Emailv31.Message.SUBJECT, "Your email flight plan!")
                    .put(Emailv31.Message.TEXTPART, "Dear passenger 1, welcome to Mailjet! May the delivery force be with you!")
                    .put(Emailv31.Message.HTMLPART, "<h3>Dear passenger 1, welcome to <a href=\"https://www.mailjet.com/\">Mailjet</a>!</h3><br />May the delivery force be with you!")));
      response = client.post(request);
      System.out.println(response.getStatus());
      System.out.println(response.getData());
    }
}
```

Go
```go
/*
This call sends a message to one recipient.
*/
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",
          },
          mailjet.RecipientV31 {
            Email: "passenger2@mailjet.com",
            Name: "passenger 2",
          },
        },
        Cc: &mailjet.RecipientsV31{
          mailjet.RecipientV31 {
            Email: "copilot@mailjet.com",
            Name: "Copilot",
          },
        },
        Bcc: &mailjet.RecipientsV31{
          mailjet.RecipientV31 {
            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 := mailjet.MessagesV31{Info: messagesInfo }
	res, err := m.SendMailV31(&messages)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("Data: %+v\n", res)
}
```

C#
```csharp
using Mailjet.Client;
using Mailjet.Client.Resources;
using System;
using Newtonsoft.Json.Linq;
namespace Mailjet.ConsoleApplication
{
   class Program
   {
      /// <summary>
      /// This call sends a message to one recipient.
      /// </summary>
      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"}
                   },
                  new JObject {
                   {"Email", "passenger2@mailjet.com"},
                   {"Name", "passenger 2"}
                   }
                  }},
                 {"Cc", new JArray {
                  new JObject {
                   {"Email", "copilot@mailjet.com"},
                   {"Name", "Copilot"}
                   }
                  }},
                 {"Bcc", new JArray {
                  new JObject {
                   {"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!"}
                 }
                });
         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()));
         }
      }
   }
}
```

### API response

```
{
  "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"
        }
      ]
    }
  ]
}
```