You can add as many of the SMTP API methods as you want to a single large JSON string, and pass that JSON string to SendGrid with your messages. To do this, add the JSON string to your message under a header named “X-SMTPAPI” like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
The above example is formatted for readability. Headers must be wrapped to keep the line length under 72. By RFC 821 no line can be longer than 1,000, so if you are going to generate this string yourself it is a good idea to make sure that you wrap it.
Here is a full example of generating the above JSON header in a Perl script:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
While there is a hard limit of 10,000 addresses that can be sent to in a multiple recipient e-mail, it is best to split up large jobs to around 1,000 recipients, to better allow for the processing load to be distributed. Furthermore, if you have a large number of additional substitutions or sections in the headers, it is best to split the send into even smaller groups.
When using the X-SMTPAPI to send to multiple recipients, you cannot use the standard SMTP protocols “TO” field to send to multiple recipients because doing so can generate duplicate messages to the addresses listed in both. For more information on this, read RFC 821.
Ensure that the header is limited to a maximum total line length of 1,000 characters. Failure to do this can cause intermediate MTA’s to split the header on non-space boundaries, which will cause spaces to be inserted in the final resulting e-mail. Additionally, if your e-mail is going through another MTA before reaching SendGrid, it is likely to have an even lower setting for maximum header length and may truncate the header.
When using the API, if our system encounters a parsing error the message will be bounced to the address specified in the MAIL FROM portion of the SMTP session. The MAIL FROM address is re-written when we send e-mail out for final delivery, so it is safe to set this to an address that can receive the bounces so that you will be alerted to any errors. More info: Bounce Forwarding
When sending unicode characters via the SMTP API, you should escape these characters using the
\u escape character. When you do this, unicode characters like
\u00E1. To see a list of unicode characters in the Wikipedia’s Unicode Article.