Temp mail
in Java.
Disposable email inboxes in Java, from a single HTTP call.
var http = HttpClient.newHttpClient();
var req = HttpRequest.newBuilder()
.uri(URI.create("https://evilmail.pro/api/temp-email"))
.header("X-API-Key", System.getenv("EVILMAIL_KEY"))
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString("{\"ttlMinutes\":30}"))
.build();
var body = http.send(req, HttpResponse.BodyHandlers.ofString()).body();
// body -> {"data":{"email":"...","sessionToken":"..."}}
var email = body.replaceAll("(?s).*\"email\":\"([^\"]+)\".*", "$1");
System.out.println("Inbox: " + email);Generating a Java temp mail inbox used to mean scraping a web UI or standing up your own SMTP catch-all — with EvilMail it is one HTTP request. This page shows temp mail in Java using nothing but the built-in java.net.http.HttpClient: create a disposable inbox, poll it until a verification email lands, then read the message and pull out the OTP. It is exactly what you need to automate email verification testing in CI, exercise sign-up flows end to end, or QA password-reset codes without ever touching a real mailbox. No SDK, no dependencies — just the temp mail API and plain HTTP you can drop into any JUnit or integration suite.
Why use temp mail in Java
End-to-end signup tests
Create a fresh disposable inbox per test run so registration flows never collide. Assert that the welcome or confirmation email actually arrives before moving on.
OTP & verification codes in CI
Poll the inbox from your JUnit or integration suite and regex the 6-digit code straight out of the body. Java email verification testing becomes fully headless and repeatable.
Password-reset QA
Trigger a reset, grab the temporary email in Java, and follow the tokenized link — validating the whole loop without a shared team mailbox that fills up with test noise.
Throwaway inboxes for scrapers & bots
When a workflow needs a burner address, mint one on demand with a short TTL. The inbox self-expires, so there is nothing to clean up afterward.
The flow — Java temp mail in 3 calls
Create a disposable inbox
import java.net.URI;
import java.net.http.*;
var http = HttpClient.newHttpClient();
var key = System.getenv("EVILMAIL_KEY"); // never hard-code
var create = HttpRequest.newBuilder()
.uri(URI.create("https://evilmail.pro/api/temp-email"))
.header("X-API-Key", key)
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString("{\"ttlMinutes\":30}"))
.build();
var body = http.send(create,
HttpResponse.BodyHandlers.ofString()).body();
// {"data":{"email":"..","sessionToken":".."}}
var email = body.replaceAll("(?s).*\"email\":\"([^\"]+)\".*", "$1");
var token = body.replaceAll(
"(?s).*\"sessionToken\":\"([^\"]+)\".*", "$1");
System.out.println("Inbox " + email + " (token " + token + ")");
Poll until the email arrives
import java.util.regex.Pattern;
// Poll up to 20 times, 3s apart, until a message lands.
int uid = -1;
for (int i = 0; i < 20 && uid < 0; i++) {
var poll = HttpRequest.newBuilder()
.uri(URI.create(
"https://evilmail.pro/api/temp-email/" + token))
.header("X-API-Key", key)
.build();
var body = http.send(poll,
HttpResponse.BodyHandlers.ofString()).body();
// messages[] carries a "uid" once mail arrives
var m = Pattern.compile("\"uid\":(\\d+)").matcher(body);
if (m.find()) { // first (newest) message
uid = Integer.parseInt(m.group(1));
break;
}
Thread.sleep(3000); // wait before the next attempt
}
if (uid < 0) throw new RuntimeException("No mail after ~60s");
System.out.println("Got message uid=" + uid);
Read the message & extract the code
import java.util.regex.Pattern;
var read = HttpRequest.newBuilder()
.uri(URI.create("https://evilmail.pro/api/message/" + uid
+ "?token=" + token))
.header("X-API-Key", key)
.build();
var body = http.send(read,
HttpResponse.BodyHandlers.ofString()).body();
// data.text holds the plain-text body
var text = body.replaceAll(
"(?s).*\"text\":\"([^\"]*)\".*", "$1");
// A 6-digit OTP: \b(\d{6})\b
var otp = Pattern.compile("\\b(\\d{6})\\b").matcher(text);
if (otp.find()) System.out.println("Code: " + otp.group(1));
else System.out.println("No 6-digit code found");
Java temp mail — FAQ
Q1How do I get a temp mail address in Java?−
Send a POST to https://evilmail.pro/api/temp-email with your X-API-Key header and a JSON body like {"ttlMinutes":30}. The response returns data.email (the address) and data.sessionToken, which you keep to poll and read messages. The hero snippet above does exactly this using the built-in java.net.http.HttpClient — no external SDK required.
Q2Can I use this for automated testing?+
Yes, that is the main use case. Because everything is plain HTTP, you can create an inbox at the start of a JUnit or integration test, trigger your app's email, poll until it arrives, and assert on its contents. Give each test run its own inbox so parallel runs never share state, and use a short TTL so nothing lingers between builds.
Q3How do I extract the OTP?+
Fetch the message via GET /api/message/{uid}?token={sessionToken}, then run a regex over data.text (or data.html). A standard 6-digit code matches \b(\d{6})\b. The extract step above compiles that pattern and prints the first match — swap in your own pattern for links or differently formatted codes.
Q4Do I need an API key / are there rate limits?+
Yes, every request must send an X-API-Key header; read it from an environment variable such as EVILMAIL_KEY rather than hard-coding it. Requests are rate-limited per key, so add a small sleep between polls (the example waits 3 seconds) instead of hammering the endpoint in a tight loop.
Q5How long does the inbox live?+
You control it with the ttlMinutes field when you create the inbox — 30 minutes in these examples. Once the TTL elapses the address and its messages expire automatically, so disposable inboxes clean themselves up and there is nothing to tear down after a test run.
Temp mail in other languages
One API key. Disposable inboxes at scale.
Create unlimited throwaway addresses, poll them over HTTP, and pull verification codes straight into your tests and CI. Free to start; custom domains and higher limits on paid plans.

