6

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?

2
  • 2
    did you end up working out how to make this happen? I'm in the same boat..
    – benpage
    Apr 24, 2018 at 1:38
  • No, its still not possible without the substitution and email template. Apr 25, 2018 at 7:07

2 Answers 2

5

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"
    ]
  }
}
2
  • 1
    If you need help figuring out how to make this happen, let me know. You may want to check out the official SendGrid Java library if you want an easier way to build messages with complicated headers.
    – bwest
    Jan 27, 2016 at 15:10
  • 2
    When using a lot of data in the x-smtpapi header, you'll want to try to be efficient. If any part of your content is common to everyone, you can put that in the body as static text. If it's common to some people (or to everyone), you can also leverage Section Tags to keep your header DRYer. Jan 27, 2016 at 21:47
0

Yes, it is:

https://sendgrid.com/docs/Integrate/Code_Examples/java.html

You can just keep adding multiple 'tos' to your email, like this:

email.addTo("[email protected]")

However, you want to do it via adding multiple BCCs instead so you don't give away everyones email address.

email.addBcc("[email protected]")
1
  • 1
    All the 1500 emails are different in content and they go to one person each Jan 27, 2016 at 14:15

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.