Send product email from Java. Fit it into your existing service layer.
Send transactional email and publish lifecycle events from JVM services with the Send & Retain API.
✓Java 17's HttpClient is enough; Spring is optional.
One request, complete trace
Request
POST /api/v1/emails
Authorization: Bearer aem_…
Idempotency-Key: welcome-8f21
{ "to": "[email protected]", "template": "welcome" }
202 Accepted
{ "id": "msg_7ca31", "status": "queued" }
[ 01 / 04 ]Client contract
Use JVM conventions without adopting another framework.
Use the built-in client
Java 17 HttpClient can call the API directly; wrap it in Spring or another framework only when useful.
Send typed payloads
Use typed builders for sender, recipients, template, and props.
Handle delivery events
Take the body as a String in your controller so the HMAC covers the exact bytes.
[ 02 / 04 ]Server quickstart
Queue one email from Java.
The credential never leaves your server. The ID follows the message.
Run the client with explicit timeouts and keep the returned message ID.
var request = HttpRequest.newBuilder(URI.create(EMAIL_URL))
.header("Authorization", "Bearer " + apiKey)
.header("Content-Type", "application/json")
.header("Idempotency-Key", "welcome-" + user.id())
.POST(HttpRequest.BodyPublishers.ofString(payload))
.build();
var response = client.send(request, BodyHandlers.ofString());Accepted response
{ "id": "msg_7ca31", "status": "queued" }[ 03 / 04 ]Quickstart
Put the email call behind a durable application boundary.
Reuse one HttpClient
Configure connection and request timeouts once and load the key from server configuration.
Send from a service or worker
Queue after the business transaction succeeds, not from an entity lifecycle hook.
Persist the message ID
Correlate the accepted response with the order, account, or event that caused the send.
Production checklist
- Secrets stay server-side
- Timeout and retry policy
- Idempotent webhook handler
- Structured error logging
[ 04 / 04 ]Related
Use Java in context
Questions people ask us
Queue your first Java email.
Reuse your HTTP client and trace the accepted message beyond the request thread.