Simple SendGrid client for Java
Java
Switch branches/tags
Clone or download
Pull request Compare This branch is 4 commits behind shunjikonishi:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
dist
src
testdata
.gitignore
LICENSE.txt
README.md
pom.xml

README.md

sendgrid4j

Overview

Simple SendGrid client for Java

Dependency

This library requires following jars.

JavaDoc

http://oss.flect.co.jp/apidocs/sendgrid4j/index.html

Usage

Send mail

SendGridClient client = new SendGridClient(USERNAME, PASSWORD);
WebMail mail = new WebMail();
//Set from and to information
mail.setFrom("test@flect.co.jp");
mail.setTo("test@flect.co.jp");
mail.setFromName("test");
mail.setToName("test");

//Subject and text(or You can use setHtml)
mail.setSubject("Test - " + new Date());
mail.setText("This is a test mail");

//Category(X-SMTPAPI option)
mail.setCategory("test");

client.mail(mail);

Get bounces

SendGridClient client = new SendGridClient(USERNAME, PASSWORD);

Bounce.Get request = new Bounce.Get();
request.setDays(7);
List<Bounce> list = client.getBounces(request);
for (Bounce bounce : list) {
    System.out.println(bounce.getEmail());
}

Get statistics

SendGridClient client = new SendGridClient(USERNAME, PASSWORD);
Statistic.Get request = new Statistic.Get();
//request.setCategory("test");
request.setDays(10);
List<Statistic> list = client.getStatistics(request);
for (Statistic stat : list) {
    System.out.println("Statistics: " + 
        stat.getDate() + ", " +
        "Category = " + stat.getCategory() + ", " +
        "Requests = " + stat.getRequests() + ", " +
        "Bounces = " + stat.getBounces() + ", " +
        "Clicks = " + stat.getClicks() + ", " +
        "Opens = " + stat.getOpens() + ", " +
        "SpamReports = " + stat.getSpamReports() + ", " +
        "UniqueClicks = " + stat.getUniqueClicks() + ", " +
        "UniqueOpens = " + stat.getUniqueOpens() + ", " +
        "Blocked = " + stat.getBlocked() + ", " +
        "Delivered = " + stat.getDelivered() + ", " +
        "Unsubscribes = " + stat.getUnsubscribes() + ", " +
        "InvalidEmails = " + stat.getInvalidEmails() + ", " +
        "RepeatUnsubscribes = " + stat.getRepeatUnsubscribes() + ", " +
        "SpamDrops = " + stat.getSpamDrops() + ", " +
        "RepeatBounces = " + stat.getRepeatBounces() + ", " +
        "RepeatSpamReports = " + stat.getRepeatSpamReports() + ", " +
        "");
}

Each class is a simple wrapper of WebAPI parameters or a JSON response.
Please see the SendGrid WebAPI documentation for details of each property.

http://sendgrid.com/docs/API_Reference/Web_API/index.html

All methods are called from SendGridClient class,
so you can understand what this can do by seeing SendGridClient.java.

License

MIT