Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
79 lines (56 sloc) 3.16 KB


Fluent Mail API is a simple Java API that uses Sun’s JavaMail API to send e-mail messages.

This is a project to demonstrate Fluent Interfaces usage, although it’s fully functional and production-ready. The API consists in an internal DSL to send e-mail messages that was designed to be dead-simple to use.

Usage example

new EmailMessage()
    .withSubject("Fluent Mail API")
    .withBody("Demo message")

Comparison with JavaMail API

If you use pure JavaMail API, it will be something like this (from Java World tutorial):

// create some properties and get the default Session
Properties props = new Properties();
props.put("", _smtpHost);
Session session = Session.getDefaultInstance(props, null);
// create a message
Address replyToList[] = { new InternetAddress(replyTo) };
Message newMessage = new MimeMessage(session);
if (_fromName != null)
    newMessage.setFrom(new InternetAddress(from,
        _fromName + " on behalf of " + replyTo));
    newMessage.setFrom(new InternetAddress(from));
    newMessage.setRecipients(Message.RecipientType.BCC, _toList);
// send newMessage
Transport transport = session.getTransport(SMTP_MAIL);
transport.connect(_smtpHost, _user, _password);
transport.sendMessage(newMessage, _toList);

20 second tutorial

1) Get the JARs

Download the latest fluent-mail-api.jar (check all the releases available at the builds directory) and mail.jar. You can also download mail.jar from JavaMail API website.

2) Configuration

You can configure Fluent Mail API in two ways:

Create a simple file and make it available in the classpath. Example:


Configure it programatically in your application startup:

EmailTransportConfiguration.configure("", true, false, "gc", "mypasswd");

3) That’s it!

You are ready to start using the API!


  • Really simple to use API.
  • Send email to, cc or bcc multiple addresses.
  • SMTP authentication support.
  • Secure SMTP support.
  • Send e-mail with attachments. (contribution by danielbussade)


Fluent Mail API is free software licensed under the Apache 2.0 License. For more details, check LICENSE.txt.