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.
new EmailMessage()
.from("demo@guilhermechapiewski.com")
.to("destination@address.com")
.withSubject("Fluent Mail API")
.withBody("Demo message")
.send();
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);
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.
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");
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.