Skip to content

Fluent Mail API is a simple Java API that uses Sun's JavaMail API and a fluent interface/internal DSL to send e-mail messages.

License

Notifications You must be signed in to change notification settings

guilhermechapiewski/fluent-mail-api

Repository files navigation

About

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()
    .from("[email protected]")
    .to("[email protected]")
    .withSubject("Fluent Mail API")
    .withBody("Demo message")
    .send();

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("mail.smtp.host", _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));
else
    newMessage.setFrom(new InternetAddress(from));
    newMessage.setReplyTo(replyToList);
    newMessage.setRecipients(Message.RecipientType.BCC, _toList);
    newMessage.setSubject(subject);
    newMessage.setSentDate(sentDate);
// 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 fluent-mail-api.properties file and make it available in the classpath. Example:

smtp.server=my.smtp.server.com
auth.required=true
use.secure.smtp=false
smtp.username=gc
smtp.password=mypasswd

OR

Configure it programatically in your application startup:

EmailTransportConfiguration.configure("my.smtp.server.com", true, false, "gc", "mypasswd");

3) That’s it!

You are ready to start using the API!

Features

  • 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)

License

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

About

Fluent Mail API is a simple Java API that uses Sun's JavaMail API and a fluent interface/internal DSL to send e-mail messages.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages