Send email with Java

JavaMail wants a Session, Properties, a Transport, and a MimeMessage. Sending email from Java is one HttpRequest with the client the JDK already ships.

Verified By Kam Low, Co-founder · Updated

The JavaMail way, and the shorter one

JavaMail (now Jakarta Mail) is fine software from a different era: Properties objects, Session factories, MimeMessage assembly, Transport.send. Pages of ceremony for one email, plus SMTP credentials to manage.

java.net.http.HttpClient has shipped with the JDK since 11. One request replaces the ceremony.

One POST, and the send is handled

JavaPOST /v1/my/messages
var body = """
  {"from":"[email protected]","to":"[email protected]",
   "subject":"Welcome","html":"<p>You're in.</p>"}""";

HttpRequest.newBuilder()
  .uri(URI.create("https://api.nitrosend.com/v1/my/messages"))
  .header("Authorization", "Bearer " + System.getenv("NITROSEND_API_KEY"))
  .POST(HttpRequest.BodyPublishers.ofString(body))
  .build();

Spring shop? The same POST through RestClient or WebClient, and you can delete spring-boot-starter-mail from the pom entirely.

If your team worries about what agent-driven email means for control, here is our own usage data: the two screens with the highest human dwell time on the platform are the campaign editor and the flow editor. That is where people approve, tweak, and ship what agents built. The machines draft. The humans sign.

For teams that want typed clients rather than hand-built requests: the full OpenAPI spec lives at api.nitrosend.com/openapi.yaml, kept validated on every change. Point your generator at it and get a Java client that matches the API exactly.

Two enterprise details we built deliberately, because enterprise users asked for them on calls: multiple custom sending domains on one account, without the old hack of splitting your company into fake brands to get them, and a billing model designed around the 500,000 to 4,000,000 emails a month band rather than treating that volume as an edge case.

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

Python Node.js PHP Go Rust +5
send.py requests ยท stdlib-adjacent
import requests

requests.post(
  "https://api.nitrosend.com/v1/messages",
  headers={"Authorization": f"Bearer {KEY}"},
  json={"to": to, "subject": subj,
        "html": body})
202 ACCEPTED
{ "id": "msg_9f2c",
  "status": "accepted" }

And the part no library gives you

The same account exposes an MCP server, so the agent writing your code can also run your email. Point Claude, Cursor, or Codex at api.nitrosend.com/mcp and it composes, previews, and stages sends, with a human approving every one. The API is for your code. The MCP is for your agent. One platform either way.

Every send comes back with a message ID, and delivery events follow on your webhook: delivered, opened, bounced. No dashboard required to know what happened. If you are staying on SMTP, how to set up SMTP is the setup to follow, and SPF, DKIM and DMARC authentication is what stops those sends landing in spam.

Go deeper

Step back from the boilerplate for a moment. The real fix for "how do I send email in Java" is not a lighter HttpRequest builder, it is skipping the builder entirely. Describe the send to Claude, Cursor, or Codex and our MCP server handles it on the same account and key, no Maven dependency and no request object to assemble.

FAQ

How do I send email from Java?

One HTTP POST with java.net.http.HttpClient: JSON body with from, to, subject, and html, bearer token header. No JavaMail Session, no SMTP properties, no Transport.

Do I still need spring-boot-starter-mail?

Not for sending through an email API. The starter wires JavaMail over SMTP; the API path is a plain HTTP call through the client you already use, with delivery events included.

First send in thirty seconds.

Simple pricing. Unlimited contacts.

Every plan includes full stack emailing: Flows, Newsletter Campaigns and Transactional Email, plus our NitroWheel LLM and all agent integrations (Claude, ChatGPT, Codex, Cursor and others). Pay for what you send, not who you store.

Daily allowances depend on your plan and sender standing. Strong list, domain and delivery evidence can raise standing, including on day one. Trusted receives the full plan allowance; available email credits, safety checks and delivery pacing still apply.

Free
$0
forever
  • Emails 8,000then 500/mo
  • Email types Transactional & Marketing
  • AI actions 20/mo
  • Contacts Free & Unlimited
  • Brands 3
  • Seats 1
  • Recipients / rolling 24h 100โ€“5,000
  • Email validation Prepaid only
Start free
Ultra
$100
per month
  • Emails 125,000/month
  • AI actions 5,000/mo
  • Brands 10
  • Seats 10 · Domains 10
  • Frontier AI Included
  • Dedicated IP Available
  • Recipients / rolling 24h 1,000โ€“625,000
  • Email validation Prepaid only
Get started
Enterprise
$300
per month
  • AI actions Unlimited
  • Unlimited brands & domains Included
  • SSO / SAML Included
  • 99.9% SLA Included
  • Recipients / rolling 24h Contracted
  • Email validation Prepaid only
Get started

Free forever. No credit card required. See full comparison →