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.
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:
| Limit | Value |
|---|---|
| Personalizations per request | 1,000 |
| Total recipients (to, cc, bcc) per request | 1,000 |
| Request body size | about 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.
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:
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.
The service below splits recipients into chunks of 1,000, builds one personalization per recipient, and sends each chunk in a single request.
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.
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:
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.
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:
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.
Up to 1,000 personalizations per request at the time of writing. Split larger lists into chunks.
Not when each recipient has its own personalization. They do if you add many addresses to the same personalization's to list.
No. It means the request was accepted for processing. Use the Event Webhook to track delivered, bounced and dropped events.
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.
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.