Coder Social home page Coder Social logo

guilhermechapiewski / fluent-mail-api Goto Github PK

View Code? Open in Web Editor NEW
38.0 5.0 17.0 1.22 MB

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: Apache License 2.0

Java 100.00%

fluent-mail-api's Introduction

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.