Personalizations
When sending an email with the v3 Mail Send endpoint, you define the various metadata about your message, like the recipients, sender, and subject, at the root level of a JSON request body. With Personalizations, you can override these various metadata for each email in an API request.
In the request body, you express Personalizations as an array of objects. The personalizations array workslike the envelope of a letter: the fields defined within personalizations apply to each email, not the recipient. Like an envelope, personalizations identify who should receive the email and how you want Twilio to handle the email.
Personalizations limit
Each API request has a limit of 1,000 personalization objects. To include more than 1,000, divide the objects across multiple API requests.
In the personalizations array, you can define:
| Property | Necessity | Purpose |
|---|---|---|
to | Required | The recipients of your email. |
cc | Optional | The recipients of your email. |
bcc | Optional | The recipients of your email. |
from | Optional | The sender or return path address of your email. |
subject | Optional | The subject line of your email. |
headers | Optional | Any headers you want in your email. |
substitutions | Optional | Any substitutions you want for your email. |
custom_args | Optional | Any custom arguments you want in your email. |
send_at | Optional | A specific time to send your email. |
With the personalizations array, you can specify different handling instructions for different copies of your email.
Send messages at different times to different recipients
To send the same email to both john@example.com and jane@example.com but set each email to be delivered at different times.
1{2"from": "sender@example.com",3"template_id": "YOUR TEMPLATE ID",4"personalizations": [{5"to": [{6"email": "john@example.com"7}],8"send_at": 16001888129},10{11"to": [{12"email": "jane@example.com"13}],14"send_at": 160027547115}]16}
- Some properties can be defined both at the root level of the request body, or per message level, and at the
personalizationslevel.- These properties include
from,subject,headers,custom_arg, andsend_at.
- These properties include
- Individual fields within the
personalizationsarray override any message-level properties defined outside ofpersonalizations. - Keys within objects such as
custom_argsget merged. If any of the keys conflict, the keys in thepersonalizationsobjects replace the message level object's keys. - No email address in any of the
to,cc, orbccproperties can repeat within the samepersonalizationsarray. - Limit of 150 substitutions per personalization block.
The following examples show how to use personalizations for common use cases, including sending to a single recipient, adding CC and BCC recipients, sending to multiple recipients, and sending from multiple senders.
The following example shows you what the personalization property would look like if you wanted to send one email to one recipient.
1{2"personalizations": [{3"to": [{4"email": "recipient1@example.com"5}],6"cc": [{7"email": "recipient2@example.com"8}],9"subject": "YOUR SUBJECT LINE GOES HERE"10}]11}
To send one email to three different recipients, follow this example:
1{2"personalizations": [{3"to": [{4"email": "recipient1@example.com"5},{6"email": "recipient2@example.com"7},{8"email": "recipient3@example.com"9}],10"subject": "YOUR SUBJECT LINE GOES HERE"11}]12}
All recipients can see all other recipients to the email.
To send email messages from more than one sender, use personalizations.
- Set a
from.emailproperty at the root level of the request body. - Add more
from.emailaddresses in thepersonalizationsarray. - If a personalization object doesn't contain a
from.emailproperty, Twilio SendGrid uses the email address in thefrom.emailproperty in the root level of the request body.
Email address restrictions
Twilio SendGrid rejects requests from a sending domain under two conditions:
- The domain of the
from.emailandpersonalizations.from.emaildon't match. All email messages must come from the same sending domain. - The sneding domain hasn't undergone domain authentication.
If these domains don't match or haven't been authenticated, Twilio SendGrid rejects the request.
To send email messages using multiple From addresses, following this example:
1// This is valid2{3"from": {4"email": "support@example.com"5},6"personalizations": [{7"from": {8"email": "noreply@example.com"9}10}]11}
1// This is invalid2{3"from": {4"email": "support@example.com"5},6"personalizations": [{7"from": {8"email": "noreply@differentexample.com"9}10}]11}