[API v3] Mailjet Java API Wrapper
Java
Latest commit 30254f1 Oct 24, 2016 @Aridjar Aridjar update pom.xml

README.md

alt text

Mailjet Java Client

Build Status

This repo features the Brand new Java wrapper for the Mailjet API. Check out the Offical Documentation

Getting Started

Installation (Maven)

Add the following in your pom.xml

    <dependencies>
        <dependency>
            <groupId>com.mailjet</groupId>
            <artifactId>mailjet-client</artifactId>
            <version>4.0.5</version>
        </dependency>
    </dependencies>

Grab your keys here

MailjetClient client = new MailjetClient(System.getenv("MJ_APIKEY_PUBLIC"), System.getenv("MJ_APIKEY_PRIVATE"));

Requests are easy to understand

MailjetRequest request = MailjetRequest(resource, id, actionId)

GET requests

List all your contacts

MailjetRequest contacts;
MailjetResponse response;

contacts = new MailjetRequest(Contact.resource);
response = client.get(contacts);

Filtering resources

MailjetRequest contacts;
MailjetResponse response;

contacts = new MailjetRequest(Contact.resource)
            .filter(Contact.LIMIT, 2);

response = client.get(contacts);

View a single resource

MailjetRequest contacts;
MailjetResponse response;

contacts = new MailjetRequest(Contact.resource, id);

response = client.get(contacts);

POST requests

Post a new sender

MailjetRequest contacts;
MailjetResponse response;

sender = new MailjetRequest(Sender.resource)
            .property(Sender.EMAIL, "dummy@mailjet.com");

response = client.post(sender);

Send an Email

MailjetRequest email;
JSONArray recipients;
MailjetResponse response;

recipients = new JSONArray()
                .put(new JSONObject().put(Contact.EMAIL, "roger@mailjet.com"))
                .put(new JSONObject().put(Contact.EMAIL, "stan@mailjet.com"))
                .put(new JSONObject().put(Contact.EMAIL, "francine@mailjet.com"));

email = new MailjetRequest(Email.resource)
                    .property(Email.FROMNAME, "Guillaume")
                    .property(Email.FROMEMAIL, "dummy@email.fr")
                    .property(Email.SUBJECT, "Subject")
                    .property(Email.TEXTPART, "Java is coming!...")
                    .property(Email.RECIPIENTS, recipients)
                    .property(Email.MJCUSTOMID, "JAVA-Email");

response = client.post(email);

Get and update a Sender

MailjetRequest getSender = new MailjetRequest(Sender.resource)
                                .filter(Sender.EMAIL, "email adress");

MailjetResponse senders = client.get(getSender);

// Grab the first sender
JSONObject sender = senders.getData().getJSONObject(0);

// Change the name
MailjetRequest update = new MailjetRequest(Sender.resource, sender.getLong("ID"))
                    .setBody(sender.put(Sender.NAME, "new name"));

System.out.println(client.put(update));

TODO:

  • head