Java (Jakarta Mail)

Jakarta Mail with a Session and an authenticator — no framework involved.

Before you start

  • Java 11 or later
  • jakarta.mail (or javax.mail on older stacks)

1Open a session and send

Your sandbox credentials
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.mailclutch.com");
props.put("mail.smtp.port", "587");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");

Session session = Session.getInstance(props, new Authenticator() {
    @Override
    protected PasswordAuthentication getPasswordAuthentication() {
        return new PasswordAuthentication("mc_0000000000000000", "pw_0000000000000000");
    }
});

Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("staging@example.com"));
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse("anyone@example.com"));
message.setSubject("Sandbox check");
message.setText("Hello from Java.");

Transport.send(message);

Watch it land

Open the sandbox and the message is there — rendered HTML, plain text, raw source, attachments, and the SPF, DKIM and DMARC verdicts. It updates live, so you can leave it open next to your terminal.

Nothing is ever delivered onward, whatever address you send to; claim the inbox with an account and it stays.

Awaiting your email

Send from any address; it stops here rather than going onward. The inbox keeps what it catches for 24 hours.

What usually goes wrong

  • mail.smtp.auth must be a string

    Properties is a string map. props.put("mail.smtp.auth", true) with a boolean is ignored, and the session then tries to send unauthenticated.

  • javax or jakarta

    The package moved from javax.mail to jakarta.mail in Jakarta EE 9. The code is otherwise identical — only the imports change.

Official documentationJakarta Mail (opens in a new tab)