Home/Email API/Spring Boot mail

spring-boot-starter-mail, or one REST call

The mail starter wires JavaMail over SMTP into your Spring app: dependency, five properties, a JavaMailSender bean. The alternative is a POST through the RestClient you already have.

Verified By Kam Low, Co-founder · Updated

What the starter actually wires

spring-boot-starter-mail autoconfigures a JavaMailSender from spring.mail.host, port, username, password, and the STARTTLS flag. It is tidy Spring, and it is still SMTP underneath: credentials in config, a protocol conversation per send, and silence after the handoff.

application.ymlthe config tax
spring:
  mail:
    host: smtp.example.com
    port: 587
    username: user
    password: pass
    properties.mail.smtp.starttls.enable: true

The RestClient alternative

Spring 6 ships RestClient; Boot apps already have an HTTP story. One POST replaces the starter, the properties, and the bean.

Java · SpringPOST /v1/my/messages
restClient.post()
  .uri("https://api.nitrosend.com/v1/my/messages")
  .header("Authorization", "Bearer " + apiKey)
  .body(Map.of("from", "[email protected]", "to", "[email protected]",
               "subject", "Welcome", "html", "<p>You're in.</p>"))
  .retrieve();

One credential story instead of five properties: the REST API and the MCP server use the same API key. Your Spring service and the agent that maintains it authenticate with one secret, rotated in one place.

We take key scoping seriously enough that it once broke us in a useful way. A customer connected a least-privilege, mail-send-only key from another provider, and our connection test kept reporting it invalid, because the probe called an endpoint that needed broader permissions. We rewrote the check to validate against an endpoint any valid key can read. A platform that punishes minimum-permission keys is training its users to over-scope, and that fix always belongs on the platform side, never in your credentials.

The same posture runs through the mail path your POST lands on. Our relay keeps TCP 2525 firewall-restricted to the API host, requires TLS and exact SMTP authentication on every connection, HMAC-signs each one-recipient route and MX snapshot, and rejects unsigned or replayed requests. Spring teams that have been burned by a permissive internal relay will know exactly why each of those is there.

Full parameters and responses live in the REST API docs and the API reference.

The trap
Gmail app password
abcd efgh ijkl mnop
✕ 500 emails/day cap
✕ breaks when 2FA settings change
✕ a full-inbox credential in your code
The fix
POST /v1/messages
Authorization: Bearer ns_live_…
✓ scoped API key, revoke anytime
✓ Free plan, unlimited contacts
✓ delivery events you can act on

Go deeper

The starter and the RestClient call above both work, but neither is the deeper point. Describe the send to Claude, Cursor, or Codex and our MCP server drafts and sends it on the same account and key, no application.yml block and no bean to configure.

The dependency-free JDK version: send email with Java. The port you pick matters less than the records behind it, so read SMTP ports alongside SPF, DKIM and DMARC authentication.

FAQ

How do I send email from Spring Boot?

Either spring-boot-starter-mail with SMTP properties and a JavaMailSender, or one RestClient POST to an email API with a bearer token. The API path drops the dependency, the credentials, and adds delivery events.

Do I need spring-boot-starter-mail?

Only if you must send over SMTP. For platform sending, a plain HTTP call through RestClient or WebClient is less configuration and more observable.

First send in thirty seconds.

Unlimited contacts. Choose your sending volume.

Campaigns, flows and transactional email on every plan. See current prices, included allowances and prepaid services.

Compare plans → · Pricing for agents