Skip to contentSkip to navigationSkip to topbar
Rate this page:
On this page

Mail Send



Operation overview

operation-overview page anchor

POST/v3/mail/send

Base url: https://api.sendgrid.com

The Mail Send operation allows you to send email over SendGrid's v3 Web API

For an overview of this API, including its features and limitations, please see the Mail Send API overview page

The overview page also includes links to SendGrid's Email API quickstarts and helper libraries to get you working with this endpoint even faster.


Authentication

authentication page anchor
Property nameTypeRequiredDescription
Authorizationstringrequired
Default: Bearer <<YOUR_API_KEY_HERE>>

Content-Encodingenum<string>Optional

Use this header when sending a gzip compressed mail body. Mail body compression is available to some high volume accounts. Submit a request to support(link takes you to an external page) to have gzip enabled on your account.

Possible values:
gzip
SchemaExample
Property nameTypeRequiredDescriptionChild properties
personalizationsarray[object]required

An array of messages and their metadata. Each object within the personalizations array can be thought of as a mail envelope—it defines who should receive an individual message and how that message should be handled. See Personalizations for more information.


fromobjectrequired

reply_toobjectOptional

reply_to_listarray[object]Optional

An array of recipients to whom replies will be sent. Each object in this array must contain a recipient's email address. Each object in the array may optionally contain a recipient's name. You can use either the reply_to property or reply_to_list property but not both.


subjectstringOptional

The global or message level subject of your email. Subject lines set in personalizations objects will override this global subject line. See line length limits specified in RFC 2822(link takes you to an external page) for guidance on subject line character limits.

Min length: 1

contentarray[object]Optional

An array of objects, each containing a message body's content and MIME type(link takes you to an external page). You must specify at least one MIME type and may include multiple. To include more than one MIME type, add an object for each type to the array.


attachmentsarray[object]Optional

An array of objects where you can define any attachments to be included with the message. Each object contains a content property, which must be a Base64 encoded string of the attachment itself, and type, filename, disposition, and content_id properties that tell SendGrid how to handle the attachment.


template_idstringOptional

An email template ID. A template that contains a subject and content—either text or html—will override any subject and content values specified at the personalizations or message level. If a template ID begins with d-, it is a dynamic template and will work with the dynamic_template_data property. If the template ID does not begin with d-, it is a standard SendGrid template and will work with the substitutions property. See How to Send an Email with Dynamic Templates for more information about working with templates.


headersobjectOptional

A collection of JSON property name and property value pairs allowing you to specify handling instructions for your email. You may not override the following headers: x-sg-id, x-sg-eid, received, dkim-signature, Content-Type, Content-Transfer-Encoding, To, From, Subject, Reply-To, CC, BCC.


categoriesarray[string]Optional

An array of category names assigned to this message. Categories allow you to group messages by categories you define. Categories should be used sparingly to create general groups that are relevant to you. Categories are not meant to be used to track individual mail sends. For more granular categorization and tracking, use the custom_args property. A category name cannot exceed 255 characters. See Working with Categories for more information.


custom_argsstringOptional

Values that are specific to the entire send that will be carried along with the email and its activity data. Substitutions will not be made on custom arguments, so any string that is assigned to this property will be assumed to be the custom argument that you would like to be used. This parameter is overridden by custom_args set at the personalizations level. Total custom_args size may not exceed 10,000 bytes.


send_atintegerOptional

A unix timestamp(link takes you to an external page) allowing you to specify when your email should be sent. A send cannot be scheduled more than 72 hours in advance. This property may be overridden by the send_at property set at the personalizations level.


batch_idstringOptional

An ID representing a batch of emails to be sent at the same time. Including a batch_id in your request allows you to include this email in that batch. It also enables you to cancel or pause the delivery of that batch. See the Scheduled Sends API for more information about scheduling your email.


asmobjectOptional

An object allowing you to specify how to handle unsubscribes. With SendGrid, an unsubscribe is the action an email recipient takes when they opt-out of receiving your messages. A suppression is the action you take as a sender to filter or suppress an unsubscribed address from your email send. From the perspective of the recipient, your suppression is the result of their unsubscribe. See Suppression Groups for more information.


ip_pool_namestringOptional

The IP Pool that you would like to send this email from. IP Pools allow you to group your dedicated Twilio SendGrid IP addresses in order to have more control over your deliverability. See IP Pools for more information.

Min length: 2Max length: 64

mail_settingsobjectOptional

A collection of different mail settings that you can use to specify how you would like this email to be handled. Mail settings provide extra functionality to your mail send. See Mail Settings for more information.


tracking_settingsobjectOptional

Settings to determine how you would like to track the metrics of how your recipients interact with your email. See Tracking Settings for more information.

202400401403404405413500

Accepted

v3 Mail Send

v3-mail-send page anchor
Node.js
Python
C#
Java
Go
PHP
Ruby
curl

_118
const client = require('@sendgrid/mail');
_118
_118
client.setApiKey(process.env.SENDGRID_API_KEY);
_118
_118
const message = {
_118
personalizations: [
_118
{
_118
to: [
_118
{
_118
email: 'alex@example.com',
_118
name: 'Alex'
_118
},
_118
{
_118
email: 'bola@example.com',
_118
name: 'Bola'
_118
}
_118
],
_118
cc: [
_118
{
_118
email: 'charlie@example.com',
_118
name: 'Charlie'
_118
}
_118
],
_118
bcc: [
_118
{
_118
email: 'dana@example.com',
_118
name: 'Dana'
_118
}
_118
]
_118
},
_118
{
_118
from: {
_118
email: 'sales@example.com',
_118
name: 'Example Sales Team'
_118
},
_118
to: [
_118
{
_118
email: 'ira@example.com',
_118
name: 'Ira'
_118
}
_118
],
_118
bcc: [
_118
{
_118
email: 'lee@example.com',
_118
name: 'Lee'
_118
}
_118
]
_118
}
_118
],
_118
from: {
_118
email: 'orders@example.com',
_118
name: 'Example Order Confirmation'
_118
},
_118
replyTo: {
_118
email: 'customer_service@example.com',
_118
name: 'Example Customer Service Team'
_118
},
_118
subject: 'Your Example Order Confirmation',
_118
content: [
_118
{
_118
type: 'text/html',
_118
value: '<p>Hello from Twilio SendGrid!</p><p>Sending with the email service trusted by developers and marketers for <strong>time-savings</strong>, <strong>scalability</strong>, and <strong>delivery expertise</strong>.</p><p>%open-track%</p>'
_118
}
_118
],
_118
attachments: [
_118
{
_118
content: 'PCFET0NUWVBFIGh0bWw+CjxodG1sIGxhbmc9ImVuIj4KCiAgICA8aGVhZD4KICAgICAgICA8bWV0YSBjaGFyc2V0PSJVVEYtOCI+CiAgICAgICAgPG1ldGEgaHR0cC1lcXVpdj0iWC1VQS1Db21wYXRpYmxlIiBjb250ZW50PSJJRT1lZGdlIj4KICAgICAgICA8bWV0YSBuYW1lPSJ2aWV3cG9ydCIgY29udGVudD0id2lkdGg9ZGV2aWNlLXdpZHRoLCBpbml0aWFsLXNjYWxlPTEuMCI+CiAgICAgICAgPHRpdGxlPkRvY3VtZW50PC90aXRsZT4KICAgIDwvaGVhZD4KCiAgICA8Ym9keT4KCiAgICA8L2JvZHk+Cgo8L2h0bWw+Cg==',
_118
filename: 'index.html',
_118
type: 'text/html',
_118
disposition: 'attachment'
_118
}
_118
],
_118
categories: [
_118
'cake',
_118
'pie',
_118
'baking'
_118
],
_118
sendAt: 1617260400,
_118
batchId: 'AsdFgHjklQweRTYuIopzXcVBNm0aSDfGHjklmZcVbNMqWert1znmOP2asDFjkl',
_118
asm: {
_118
groupId: 12345,
_118
groupsToDisplay: [
_118
12345
_118
]
_118
},
_118
ipPoolName: 'transactional email',
_118
mailSettings: {
_118
bypassListManagement: {
_118
enable: false
_118
},
_118
footer: {
_118
enable: false
_118
},
_118
sandboxMode: {
_118
enable: false
_118
}
_118
},
_118
trackingSettings: {
_118
clickTracking: {
_118
enable: true,
_118
enableText: false
_118
},
_118
openTracking: {
_118
enable: true,
_118
substitutionTag: '%open-track%'
_118
},
_118
subscriptionTracking: {
_118
enable: false
_118
}
_118
}
_118
};
_118
_118
client
_118
.send(message)
_118
.then(() => console.log('Mail sent successfully'))
_118
.catch(error => {
_118
console.error(error);
_118
});


Rate this page: