Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sendgrid: Send multiple different emails in one request

Tags:

java

sendgrid

I'm using sendgrid java web api client from their website to send mail through the web api gateway. My problem is that i can only send one message per request and i usually have need to send 1000-1500 messages at a time which are all different in content, so I just send them in a loop. However, this makes 1000-1500 api request which is very slow.

Is it possible to send multiple individual different emails in one request?

like image 867
Tuomas Valtonen Avatar asked Sep 25 '22 13:09

Tuomas Valtonen


1 Answers

This is a bit of a workaround, but you could batch different emails together into one request by using the substitution property of the X-SMTPAPI header. In your email body, include only the substitution token, e.g. %content%. Then pass your actual content in the header, e.g.

{
  "to": [
    "[email protected]",
    "[email protected]"
  ],
  "sub": {
    "%content%": [
      "Here is the content for the email to john.doe",
      "And this is some different content for jane.doe"
    ]
  }
}
like image 116
bwest Avatar answered Oct 12 '22 11:10

bwest