Best Division

Spread Your Knowledge

  • All topics
  • About us
  • Contact us
  • Privacy policy
  • Terms of service
  • Copyright
  • Facebook
  • Twitter
  • Instagram
  • Youtube
  • LinkedIn
  • Pinterest
  • Github
  • Tumblr

© 2026 Best Division

How to Send Batch Emails with SendGrid API in Spring Boot

Java
Jayant Kumar
Jayant Kumar@jayantkumar314
PublishedDec 7, 2024
UpdatedNov 16, 2026
7 min read

To send batch emails with the SendGrid API in Spring Boot, add the sendgrid-java SDK, keep the API key in an environment variable, and build one Mail object with up to 1,000 Personalization entries, one per recipient. Posting that single request to mail/send delivers an individual message to each recipient, so nobody sees anyone else's address.

This is much faster than looping over send() once per user, and it counts as one API call against your rate limit. The code below targets Spring Boot 3.x on Java 17 or newer.

Table of Contents

  • How SendGrid handles many recipients
  • Adding the dependency and the API key
  • Creating the SendGrid client bean
  • Sending a batch with personalizations
  • Personalising each message
  • Running the batch off the request thread
  • Frequently Asked Questions
    • How many emails can I send in one SendGrid request?
    • Will recipients see each other's addresses?
    • Does a 202 response mean the emails were delivered?
    • Should I use SMTP or the Web API from Spring Boot?
  • Summary

How SendGrid handles many recipients

The v3 Mail Send endpoint accepts a personalizations array. Each element describes one outgoing message: its own to, cc, bcc, subject, custom headers and template data. The limits that matter in practice:

LimitValue
Personalizations per request1,000
Total recipients (to, cc, bcc) per request1,000
Request body sizeabout 30 MB including attachments

Check the current numbers in the SendGrid documentation before relying on them, because plans and limits change. If you have more than 1,000 recipients, split the list into chunks and send one request per chunk.

Putting several addresses in a single personalization's to list is different: every recipient then sees the others. For bulk mail you almost always want one personalization per recipient.

Adding the dependency and the API key

xml

Use the latest 4.x release from Maven Central; the version above is an example. Store the key outside the code and bind it with a typed properties record:

yaml
java

Enable the record with @ConfigurationPropertiesScan or @EnableConfigurationProperties(SendGridProperties.class) on a configuration class. Create the key in SendGrid with only the Mail Send permission so a leak does little damage.

Creating the SendGrid client bean

java

Sending a batch with personalizations

The service below splits recipients into chunks of 1,000, builds one personalization per recipient, and sends each chunk in a single request.

java

A 202 Accepted response means SendGrid queued the request, not that every message was delivered. Bounces, blocks and spam reports arrive later through the Event Webhook.

Personalising each message

For per-recipient content, use dynamic transactional templates created in the SendGrid dashboard. Pass the template ID with mail.setTemplateId(...) and add data per personalization:

java

In the template, reference the values with Handlebars syntax such as the first_name variable. This keeps HTML out of your Java code and lets non-developers edit the layout.

Running the batch off the request thread

Sending thousands of emails inside an HTTP request makes the caller wait and risks a timeout. Run the work asynchronously with @Async (add @EnableAsync to a configuration class) or hand it to a job queue:

java

For large or recurring campaigns, Spring Batch or a message broker gives you retries and restartability. Add backoff on 429 responses and retry only on 429 and 5xx status codes, never on other 4xx errors.

Frequently Asked Questions

How many emails can I send in one SendGrid request?

Up to 1,000 personalizations per request at the time of writing. Split larger lists into chunks.

Will recipients see each other's addresses?

Not when each recipient has its own personalization. They do if you add many addresses to the same personalization's to list.

Does a 202 response mean the emails were delivered?

No. It means the request was accepted for processing. Use the Event Webhook to track delivered, bounced and dropped events.

Should I use SMTP or the Web API from Spring Boot?

The Web API is the better choice for bulk sending because it supports personalizations, templates and detailed error responses. Spring's JavaMailSender over SMTP works for small volumes.

Summary

Use the sendgrid-java SDK with the key in an environment variable, build one Mail with a Personalization per recipient, and send in chunks of at most 1,000. Prefer dynamic templates for personalised content, run large sends asynchronously, and handle delivery results through webhooks.

Share

Similar posts

  • What Is an Exception in Java? Checked vs Unchecked Exceptions
  • What Are Sealed Interfaces and Records Together in Java Domain Models?
  • Association vs Aggregation vs Composition in Java Explained
  • What Is Composition vs Inheritance in Java and Which Should You Prefer?
  • What Is the equals and hashCode Contract in Java?
  • What Is the Object Class in Java? equals, hashCode and toString
  • What Is Method Overriding in Java and How Is It Different from Overloading?
  • What Is Polymorphism in Java? Compile-Time vs Runtime