When sending an email with the v3 Mail Send endpoint, you define the various metadata about your message, such as the recipients, sender, subject, and send time, at the root level of a JSON request body. Personalizations allow you to override these various metadata for each email in an API request.
Personalizations is an array of objects. Think of the personalizations array like the envelope of a letter: the fields defined within personalizations apply to each email, not the recipient. Like an envelope, personalizations are used to identify who should receive the email as well as details about how you would like the email to be handled. For example, you can define when you would like it to be sent, what headers you would like to include, and any substitutions or custom arguments you would like to be included with the email.
Personalizations allow you to define:
You must include at least one to
object within the personalizations array.
Since the personalizations
property is an array, you may include multiple objects allowing you to specify different handling instructions for different copies of your email. For example, you could 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@yourdomain.com",3"template_id": "YOUR TEMPLATE ID",4"personalizations": [5{6"to": [7{8"email": "john@example.com"9}10],11"send_at": 160018881212},13{14"to": [15{16"email": "jane@example.com"17}18],19"send_at": 160027547120}21]22}
You may not include more than 1000 personalizations per API request. If you need to include more than 1000 personalizations, please divide these across multiple API requests.
Some properties can be defined both at the root level of the request body (message level) and at the personalizations level.
For example, the from
, subject
, headers
, custom_arg
, and send_at
properties can all be defined at the message level or at the personalizations level. Individual fields within the personalizations
array will override any message level properties that are defined outside of personalizations. For example, the email subject defined within personalizations will override the subject defined at the message level in the JSON payload.
Keys within objects such as custom_args
will be merged. If any of the keys conflict, the keys in the personalizations
object will replace the message level object's keys.
All of the recipients in a single personalization object (specified in the to
, cc
, or bcc
fields) will see the same email, as defined by the data in that personalization. Because of this, SendGrid does not allow duplicate email addresses among these three recipient arrays in a single personalization.
Below are some examples of how you can use personalizations for various use cases.
The following example shows you what the personalization property would look like if you wanted to send a single email to a single recipient.
1{2"personalizations": [3{4"to": [5{6"email": "recipient1@example.com"7}8],9"cc": [10{11"email": "recipient2@example.com"12}13],14"subject": "YOUR SUBJECT LINE GOES HERE"15}16]17}
The following example shows you what the personalization property would look like if you wanted to send a single email to a single recipient with substitutions.
1{2"personalizations": [3{4"to": [5{6"email": "recipient@example.com"7}8],9"substitutions": {10"%fname%": "recipient",11"%CustomerID%": "CUSTOMER ID GOES HERE"12},13"subject": "YOUR SUBJECT LINE GOES HERE"14}15]16}
The following example shows how to send one email to recipient1@example.com
with a carbon copy sent to recipient2@example@com
. Both emails will have the same headers.
1{2"personalizations": [3{4"to": [5{6"email": "recipient1@example.com"7}8],9"cc": [10{11"email": "recipient2@example.com"12}13],14"subject": "YOUR SUBJECT LINE GOES HERE"15}16]17}
The following example shows how to send one email to recipient1@example.com
with a CC sent to recipient2@example.com
and a BCC sent to recipient3@example.com
.
1{2"personalizations": [3{4"to": [5{6"email": "recipient1@example.com"7}8],9"cc": [10{11"email": "recipient2@example.com"12}13],14"bcc": [15{16"email": "recipient3@example.com"17}18]19}20]21}
The following shows how to send one email to three different recipients: recipient1@example.com
, recipient2@example.com
, and recipient3@example.com
. These recipients will all be able to see each other on the email.
1{2"personalizations": [3{4"to": [5{6"email": "recipient1@example.com"7},8{9"email": "recipient2@example.com"10},11{12"email": "recipient3@example.com"13}14],15"subject": "YOUR SUBJECT LINE GOES HERE"16}17]18}
The following shows what personalizations are required to send the same email to one recipient, with multiple CCs and BCCs.
1{2"personalizations": [3{4"to": [5{6"email": "recipient1@example.com"7}8],9"cc": [10{11"email": "recipient2@example.com"12},13{14"email": "recipient3@example.com"15},16{17"email": "recipient4@example.com"18}19],20"subject": "YOUR SUBJECT LINE GOES HERE"21}22]23}
The following shows how to send two different emails to two different groups of recipients.
1{2"personalizations": [3{4"to": [5{6"email": "recipient1@example.com"7}8],9"cc": [10{11"email": "recipient2@example.com"12},13{14"email": "recipient3@example.com"15},16{17"email": "recipient4@example.com"18}19],20"subject": "YOUR SUBJECT LINE GOES HERE"21},22{23"to": [24{25"email": "recipient5@example.com"26}27],28"cc": [29{30"email": "recipient6@example.com"31},32{33"email": "recipient7@example.com"34},35{36"email": "recipient8@example.com"37}38],39"subject": "YOUR SUBJECT LINE GOES HERE"40}41]42}
It is possible to specify multiple From addresses using personalizations. If a personalization object does not contain a from
object, SendGrid will use the email
address in the from
object defined at the root level of the request body.
To successfully deliver email using multiple From addresses, the following conditions must be met.
from
object with an email
property must be specified at the root level of the request body.from
email
property specified in any personalization must match the domain of the from
email
property specified at root level of the request body—SendGrid will reject requests if these domains do not match.1// This is valid2{3"from": {4"email": "support@example.com"5},6"personalizations": [7{8"from": {9"email": "noreply@example.com"10}11}12]13}1415// This is invalid16{17"from": {18"email": "support@example.com"19},20"personalizations": [21{22"from": {23"email": "noreply@differentexample.com"24}25}26]27}
The following shows how to send multiple emails using three different from
addresses on the same domain.
You must complete domain authentication to send email from multiple addresses. SendGrid will reject requests from a sending domain that has not been authenticated.
1{2"from": {3"email": "default@samedomain.com"4},5"personalizations": [6{7"subject": "YOUR SUBJECT LINE GOES HERE",8"to": [9{10"email": "recipient1@example1.com"11}12],13"from": {14"email": "sender1@samedomain.com"15}16},17{18"subject": "YOUR SUBJECT LINE GOES HERE",19"to": [20{21"email": "recipient2@example2.com"22}23],24"from": {25"email": "sender2@samedomain.com"26}27},28{29"subject": "YOUR SUBJECT LINE GOES HERE",30"to": [31{32"email": "recipient3@example3.com"33}34],35"from": {36"email": "sender3@samedomain.com"37}38}39]40}