Send email from Java
Add app.mailset:java with Maven or Gradle, then mailset.send(Message.builder()...build()). It needs nothing beyond the JDK, and mailset.async() answers CompletableFutures.
By starting you agree to the Terms and Privacy Policy.
Install the Java SDK
Maven or Gradle, for Java 17 and later.
<dependency>
<groupId>app.mailset</groupId>
<artifactId>java</artifactId>
<version>0.7.0</version>
</dependency>
Send your first email from Java
Mailset.fromEnv() reads MAILSET_KEY. Message.builder() sets each field, .deliverBy("10m") included, so a code that can’t go out in ten minutes is refused. send answers a Sent with id() and status(), and throws MailsetException on a refusal.
import app.mailset.Mailset;
import app.mailset.Message;
import app.mailset.Sent;
// Reads MAILSET_KEY from the environment.
Mailset mailset = Mailset.fromEnv();
Sent sent = mailset.send(Message.builder()
.from("Acme <moc.elpmaxe@olleh>")
.to("gro.elpmaxe@ana")
.subject("Your Acme code")
.text("Your code is 123456.")
.html("<p>Your code is <b>123456</b>.</p>")
.deliverBy("10m")
.build());
System.out.println(sent.id() + " " + sent.status());
Delivery events in Spring Boot
Mailset reports every delivery, bounce and complaint to a URL you pick. The Spring Boot guide has the controller, which takes the body as byte[] so the signature still matches.
Send from your own domain
Your product sends as your own domain either way. What changes is where your team’s mail lives.
- Sending only. Your team’s mail stays at Google, Microsoft or wherever it is now. Mailset asks for DKIM, a bounce host and DMARC, and leaves your MX alone. Send from a domain whose mail stays elsewhere
- Mailboxes too. Your team’s mail moves to Mailset, with a real mailbox for every address on the domain and your product’s email on the same bill. Set up a domain
mailset domains add example.com --sendingmailset domains apply example.com --sendingmailset domains check example.commailset keys create --send --domain example.com --from moc.elpmaxe@olleh --name "Acme API"What the Java SDK’s build checks
Each line comes from the SDK’s own build, which fails when one stops being true.
| Fact | Detail | Known from |
|---|---|---|
| Java 17+ | The oldest its manifest allows | Its manifest |
| No dependencies | Nothing else to install beside it | Its manifest |
| Typed throughout | Immutable classes, each with a builder | A test |
| Sync and async | Mailset, and async() for futures | A test |
Where to go from here
- The Java SDKEvery task, from the client’s options to errors and retries.
- WebhooksThe events Mailset posts about your product’s email, and how to check a request’s signature.
- Give sign-in codes a deadlineUse deliverBy so a code that would arrive late is never sent.
- Retry without sending twiceMake a send safe to repeat with an idempotency key or a Message-ID.
- Handle bouncesTell a dead address from a full inbox, and keep your list clean.
- Send many messages at onceUp to 100 messages a request, each with its own answer.
Product email on every plan
- Base$29a month10 members included
- Team$79a month25 members included
- Base
Regular price $29$14.50a month10 members included - Team
Regular price $79$39.50a month25 members included
Black Friday prices, for trials started by Thursday, Dec 31. Offer terms
Both include 10,000 emails a month, your product’s and your team’s together. Past that it’s $0.40 per 1,000 with pay as you go.
Sending from Java, asked and answered
Do I need JavaMail or Jakarta Mail?
No. There’s no Session or SMTP Transport to set up: the SDK calls Mailset over HTTPS with the JDK’s own HttpClient.
Is the client thread-safe?
Yes. One Mailset holds one credential and is safe to share between threads, so make it once when the server starts.
Is there an async API?
mailset.async() is the same client, each method answering a CompletableFuture on HttpClient.sendAsync. It shares the credential and the connections.
Make a key and sendTry it on your own domain
Make a key in Settings › Developers, keep it as MAILSET_KEY, and run the example above.7 days free, with everything on. Make a key, run the example above and watch the receipt come back.
By starting you agree to the Terms and Privacy Policy.