← Back to blog

Spring Boot Transactional Email API (2026): A RestClient Service That Posts to /emails

Send transactional email from Spring Boot with Rovela’s HTTP API: a RestClient @Service, configuration properties for the Bearer key, Idempotency-Key, and documented errors. Not an OTP guide and not a @Scheduled tutorial.

Updated November 10, 2026
Spring Boot Transactional Email API (2026): A RestClient Service That Posts to /emails

Spring Boot already has an HTTP client; transactional email should use it

A Spring Boot service already calls HTTP APIs with RestClient or WebClient. The natural way to send transactional email — an invoice that is ready to view, a shipping update, a “your export is ready” note, a security alert — is the same pattern: one HTTPS POST with a Bearer key, not a JavaMail session pointed at a mailbox.

Rovela’s Email API is built for that. There is no official SDK and no starter you have to pin. The base URL is https://api.rovela.dev. You authenticate with Authorization: Bearer re_… (Authentication) and queue a message with POST /emails. The response is a message id. HTTP 200 means the message was accepted and queued, not that it has already arrived (Quick Start).

This is not a redo of a Spring Boot OTP tutorial, and it is not a @Scheduled or cron guide. If you need one-time codes, start from the existing Spring Boot OTP article and the official verification code example. Recurring sends belong in the existing scheduler coverage. This article is the everyday transactional provider: a @Service around RestClient, configuration properties for the key, an Idempotency-Key on anything a retry might repeat, and documented error handling around the {statusCode, name, message} envelope.

If you are still choosing between HTTP and SMTP, read Email API vs SMTP. Rovela’s SMTP is mailbox SMTP for mail apps (mx.rovela.dev:465, a device credential, send-as-self, 30 messages a minute from one client address). Programmatic volume from a Spring Boot process belongs on POST /emails.

A Spring Boot invoice controller injects an EmailsService that uses RestClient to POST /emails

What you need before the first Spring Boot send

The first-email guide and the Quick Start are the same five steps, whether your caller is curl or Spring Boot:

  1. Create an account. You start on the free plan, which sends real mail. There is no separate sandbox or test key.
  2. Add and verify a sending domain (a subdomain such as mail.example.com is a common choice). You cannot send from a domain you have not verified; an unverified or foreign from is refused with a 400 that names the domain. See the domain setup guide and what domain email is.
  3. Create an API key. A sending_access key can send and nothing else — the right default for production. A full_access key can also read messages and events, and manage domains, templates, and webhooks. The full key is shown once.
  4. Send with POST /emails.
  5. Confirm delivery in the dashboard, with GET /emails/:id or GET /emails/:id/events (those reads need full_access or a dashboard session), or with a webhook.

from is a string in the documented form "Acme <hello@yourdomain.com>". The address must sit on a verified sending domain. How the display name and the address work is covered in the From name guide.

At least one of html, text, or template is required. Send both html and text where you can — many clients preview the text part (HTML email API).

A RestClient @Service and configuration properties

Keep the key on the server. Never put a Rovela key in a browser bundle, a mobile app, or a public repository. A leaked sending_access key can send mail as your domain. Spring Boot configuration properties (backed by environment variables) are the right place.

# application.properties (or environment variables)
rovela.api-key=${ROVELA_API_KEY}
rovela.from=Acme <hello@mail.acme.com>
rovela.base-url=https://api.rovela.dev
// RovelaProperties.java
@ConfigurationProperties(prefix = "rovela")
public record RovelaProperties(String apiKey, String from, String baseUrl) {}
// EmailsService.java
@Service
public class EmailsService {
    private final RestClient client;
    private final RovelaProperties props;

    public EmailsService(RestClient.Builder builder, RovelaProperties props) {
        this.props = props;
        this.client = builder.baseUrl(props.baseUrl()).build();
    }

    public EmailAccepted send(String to, String subject, String html, String text,
                              String idempotencyKey, String replyTo) {
        Map<String, Object> body = new LinkedHashMap<>();
        body.put("from", props.from());
        body.put("to", to);
        body.put("subject", subject);
        body.put("html", html);
        body.put("text", text);
        if (replyTo != null && !replyTo.isBlank()) {
            body.put("reply_to", replyTo);
        }
        var spec = client.post()
            .uri("/emails")
            .header("Authorization", "Bearer " + props.apiKey())
            .contentType(MediaType.APPLICATION_JSON)
            .body(body);
        if (idempotencyKey != null && !idempotencyKey.isBlank()) {
            spec = spec.header("Idempotency-Key", idempotencyKey);
        }
        return spec.retrieve()
            .onStatus(s -> s.value() >= 400, (req, res) -> {
                throw new EmailsException(res.getStatusCode().value(),
                    new ObjectMapper().readValue(res.getBody(), Map.class));
            })
            .body(EmailAccepted.class);
    }

    public record EmailAccepted(String object, String id) {}
}

Register the properties with @EnableConfigurationProperties(RovelaProperties.class) and inject EmailsService into controllers as a normal Spring bean. There is still no official SDK; this is ordinary RestClient.

The curl equivalent of the same send, matching the Emails API and the Quick Start, is:

curl -X POST https://api.rovela.dev/emails \
  -H "Authorization: Bearer $ROVELA_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: invoice-10043-ready" \
  -d '{
    "from": "Acme <hello@mail.acme.com>",
    "to": "alice@example.com",
    "subject": "Your invoice 10043 is ready",
    "html": "<p>Invoice <b>10043</b> is ready to view.</p>",
    "text": "Invoice 10043 is ready to view."
  }'

Success looks like {"object": "email", "id": "9f1c2e40-..."}. Store that id next to the invoice in your database. You will want it when you debug a single message.

A controller that sends after a user action

Transactional mail is triggered by something the user did. A minimal invoice endpoint, with an idempotency key derived from the invoice id so a retried HTTP request does not send two notices:

@RestController
@RequestMapping("/invoices")
public class InvoiceEmailController {
    private final EmailsService emails;
    private final InvoiceRepository invoices;

    public InvoiceEmailController(EmailsService emails, InvoiceRepository invoices) {
        this.emails = emails;
        this.invoices = invoices;
    }

    @PostMapping("/{id}/email")
    public Map<String, String> emailInvoice(@PathVariable String id) {
        Invoice invoice = invoices.findById(id).orElseThrow();
        EmailsService.EmailAccepted result = emails.send(
            invoice.customerEmail(),
            "Your invoice " + invoice.number() + " is ready",
            "<p>Invoice <b>" + invoice.number() + "</b> is ready to view.</p>",
            "Invoice " + invoice.number() + " is ready to view.",
            "invoice-" + invoice.id() + "-ready",
            "Acme Billing <billing@acme.com>"
        );
        return Map.of("email_id", result.id());
    }
}

reply_to is optional and is not a substitute for a verified from. It tells the mail client where a human reply should go (Email API Reply-To). cc and bcc are also documented; they count toward the 50-recipient transport cap and toward monthly quota, because quota is charged per recipient, not per message (Email API CC and BCC).

An Idempotency-Key may be up to 256 characters. A retry of the same request within 24 hours returns the original response instead of sending again. That is the right default for anything driven by a queue, a payment webhook, or a user double-clicking “send invoice.”

Do not invent a sandbox. Free-plan keys send real mail. During development, use a verified staging subdomain and recipients you control (how to test a transactional email API).

Errors you should handle in the service

Every error uses the same shape (Quick Start, Email API error handling):

{
  "statusCode": 400,
  "name": "Bad Request",
  "message": "html or text body is required"
}

Documented cases you will actually hit from a Spring Boot app:

  • 400 — a missing required field, an unverified or foreign from domain, a template that does not exist, a base64 attachment that does not decode, or more than 50 recipients across to, cc, and bcc.
  • 401 — missing or invalid key, or a sending_access key used to read, reschedule, or cancel a message. Reading events is a full_access (or session) operation.
  • 429 — rate limit or monthly allowance exceeded. Official examples mention Retry-After. Each entry in a batch counts individually, so a large batch can trip this partway through. Sending also stops for the rest of the calendar month if you exceed the plan allowance (Pricing).

Surface the message field in your own logs as-is. Do not invent a /logs API; delivery history lives in the dashboard and, with a full_access key, on GET /emails/:id and GET /emails/:id/events.

A 403 can appear on management endpoints when the credential is valid but lacks permission. That is a different failure from a 401, and it is documented on the authentication pages. Map EmailsException to a Spring @ControllerAdvice if you want the same envelope reflected to your own API clients — still without inventing Rovela endpoints.

The Spring Boot service sends with an Idempotency-Key; a later signed webhook reports delivered or bounced, which is not a @Scheduled job

Delivery is asynchronous — do not poll from the request path

A 200 from POST /emails is not a delivery receipt. Confirm later:

  • The Emails view in the dashboard.
  • GET /emails/:id and GET /emails/:id/events with a full_access key. You are looking for email.sent followed by email.delivered, or email.bounced if the receiving server rejected it (Email delivery status API).
  • A webhook for anything in production. Verify the HMAC-SHA256 signature (webhook security). Event types include sent, delivered, delayed, bounced, complained, opened, and clicked.

Do not turn a Spring MVC handler into a polling loop against /emails/:id/events. The docs are explicit: the events endpoint is useful for debugging a single message; systematic handling belongs on a webhook. Do not replace that webhook with @Scheduled polling either — that is a different article, and it is the wrong default for delivery.

POST /emails/batch accepts up to 100 messages, each with the same schema, processed independently. template and topic_id are rejected on the batch endpoint rather than ignored — send those through POST /emails. If you schedule with scheduled_at, reading, rescheduling, and cancelling need full_access or a dashboard session; a sending_access key can only send. The dedicated scheduled email and batch transactional email guides cover those flows in full; this article will not redo them.

Templates are available if you would rather store HTML in Rovela and send { id, variables } (Templates API, templates guide). template is mutually exclusive with html and text.

What not to do in a Spring Boot codebase

Do not add JavaMailSender or a Jakarta Mail starter and point it at mx.rovela.dev for application volume. That path is for mailboxes and mail apps. A mailbox can send only as its own address, and the documented client limit is 30 messages a minute. You also lose the HTTP API’s tracking, logs, and webhooks (SMTP, Email API vs SMTP relay).

Do not create a “Rovela starter” that invents endpoints, official clients, numeric HTTP rate (req/s) figures, a sandbox flag, or a dedicated IP. Call the documented HTTP API with RestClient.

Do not put the key in query parameters or in frontend code. Create a sending_access key for the Spring Boot service. If you send for several customers from one organization, a key can be restricted to a single domain (Authentication, Email API for multi-tenant SaaS).

Do not treat @Async as a substitute for idempotency. An asynchronous method that retries after a timeout still needs an Idempotency-Key. It also does not confirm delivery; only the events API or a webhook does.

A compact Spring Boot checklist

  1. Verify the sending domain before any production from.
  2. Store a sending_access key in configuration properties; construct Authorization: Bearer … on the server.
  3. Reuse a RestClient (or a shared builder) rather than constructing a new HTTP stack on every send.
  4. Send both html and text. Set reply_to when a human should be able to answer.
  5. Put an Idempotency-Key on any send a queue, webhook, or double submit might repeat.
  6. Handle 400, 401, and 429 from the documented error envelope. Remember that 200 means queued.
  7. Subscribe to webhooks for delivery, bounces, and complaints; use GET /emails/:id/events only to debug a single message.
  8. Leave mailbox SMTP to people and mail apps. Leave @Scheduled to the scheduler article.

Once that @Service is in place, every other Spring Boot controller can inject it the same way — receipts, shipping updates, security alerts — without growing a second email stack. That is the point of a transactional email API: one authenticated HTTP call from the application you already run.