Git Product home page Git Product logo

lutung's Introduction

Lutung - Java Mandrill API

Lutung - a Java interface to the Mandrill API. All API calls are implemented thus far. Check out Mandrill's API [Documentation] (https://mandrillapp.com/api/docs/) to see all the possible magic.

Features:

  • all public API calls are implemented.
  • easy library set up; just provide your api key that you got from Mandrill.
  • all API calls are exposed through one simple interface: the MandrillApi class.
  • easy, intuitive naming scheme. All function-names are derived from the Mandrill API calls: if there is a call with the address '/messages/send.json', then we have a function for that called 'MandrillApi.messages().send(...)'.
  • API request errors are exposed to the user (you!) as a MandrillApiError.

Examples

The 'whoami' of Mandrill:

MandrillApi mandrillApi = new MandrillApi("<put ur Mandrill API key here>");

MandrillUserInfo user = mandrillApi.users().info();

// pretty-print w/ gson
Gson gson = new GsonBuilder().setPrettyPrinting().create();
System.out.println( gson.toJson(user) );

Send a 'Hello World!' email

MandrillApi mandrillApi = new MandrillApi("<put ur Mandrill API key here>");

// create your message
MandrillMessage message = new MandrillMessage();
message.setSubject("Hello World!");
message.setHtml("<h1>Hi pal!</h2><br />Really, I'm just saying hi!");
message.setAutoText(true);
message.setFromEmail("[email protected]");
message.setFromName("Kitty Katz");
// add recipients
ArrayList<Recipient> recipients = new ArrayList<Recipient>();
Recipient recipient = new Recipient();
recipient.setEmail("[email protected]");
recipient.setName("Claire Annette");
recipients.add(recipient);
recipient = new Recipient();
recipient.setEmail("[email protected]");
recipients.add(recipient);
message.setTo(recipients);
message.setPreserveRecipients(true);
ArrayList<String> tags = new ArrayList<String>();
tags.add("test");
tags.add("helloworld");
message.setTags(tags);
// ... add more message details if you want to!
// then ... send
MandrillMessageStatus[] messageStatusReports = mandrillApi
		.messages().send(message, false);

Error handling for Mandrill API errors

MandrillApi mandrillApi = new MandrillApi("<put ur Mandrill API key here>");

try {
	MandrillUserInfo user = mandrillApi.users().info();
} catch(final MandrillApiError e) {
	log.error(e.getMandrillErrorAsJson(), e);
}

Create a new template

MandrillApi mandrillApi = new MandrillApi("<put ur Mandrill API key here>");

MandrillTemplate newTemplate = mandrillApi.templates().add(
		"test_template_001", 
		"<html><body><h1>Hello World!</h1></body></html>",
		false);

Dependencies

If you use Maven, the pom file should help you with this. If you are not using Maven, make sure to put the following libraries (and their dependencies) on your classpath:

Known Issues

  • The metadata returned by the mandrill api on /messages/search.json does not get mapped to a member of MandrillMessageInfo

  • So far, I failed to successfully use Mandrills /messages/send-raw.json call. I'm not sure if I fail to create valid MIME contents, but lemme know if you make any experience with this call.

  • Also, I have no inbound-emailing set up with Mandrill. Would be great if anyone out there could test the implemented 'inbound' functionalities.

Contribute

Sure! Just shoot me an email and let me know about your ideas.

Lutung? Huh?

A monkey!!! The Javan Lutung is the name giver for this project; hat tip to MailChimp's naming scheme.

License

This library is released under the GNU Lesser General Public License http://www.gnu.org/licenses/lgpl.html.

lutung's People

Watchers

Marcos Gaeta avatar

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.