Start

Get started

Install Simple Java Mail from Maven Central, send a first email, verify the SMTP connection, and choose optional modules.

Java 8+ Apache-2.0 Maven Central

01 Add the dependency

Install Simple Java Mail.

Start with simple-java-mail. It gives you the public API and everything needed for the usual send.

pom.xmlMaven
<dependency>
    <groupId>org.simplejavamail</groupId>
    <artifactId>simple-java-mail</artifactId>
    <version>9.3.2</version>
</dependency>
Using Gradle?
implementation("org.simplejavamail:simple-java-mail:9.3.2")

Published on Maven Central. Keep the current Javadocs alongside the guide when adapting the examples.

02 Build a message

Describe the content and recipients.

Simple Java Mail chooses and builds the corresponding MIME structure.

FirstSend.javaMessage
Email email = EmailBuilder.startingBlank()
    .from("Sender", "sender@example.org")
    .withRecipients(new RecipientBuilder()
        .withName("Recipient")
        .withAddress("recipient@example.net")
        .withType(TO)
        .build())
    .withSubject("It works")
    .withPlainText("Your first Simple Java Mail message.")
    .buildEmail();

03 Configure and send

Build one reusable mailer.

Keep credentials outside the source, and choose the transport strategy that matches your SMTP service.

FirstSend.javaDelivery
Mailer mailer = MailerBuilder
    .withSMTPServer(
        System.getenv("SMTP_HOST"),
        587,
        System.getenv("SMTP_USER"),
        System.getenv("SMTP_PASSWORD"))
    .withTransportStrategy(TransportStrategy.SMTP_TLS)
    .buildMailer();

mailer.sendMail(email);

Port and transport strategy must match the server. See the transport strategy guide before adapting this example.

04 Verify the setup

Test each part separately.

Test the connection

Check the server and credentials separately from a message send.

mailer.testConnection();

Validate the message

Check the supplied email's sender, recipients, addresses, and injection-sensitive values without submitting it.

mailer.validate(email);

An SMTP server accepting a submission does not guarantee final delivery or inbox placement. The diagnostics guide separates each stage.

Add only what you need

Optional modules

The main dependency covers everyday sending. Add a module only when the application needs the feature.

Where to go next

Build, configure, or secure the mailer.