sendgrid4j

Return to index link to github

Overview

sendgrid4j is a WebAPI wrapper for SendGrid implemented by Java.

Following features are supported

  • Sending mail by WebAPI
    • Multiple attachements
    • Category
  • Retrieving Email Reports
    • Bounces
    • Blocks
    • Spam reports
    • Invalid emails
    • Unsubscribes
  • Retrieving Statistics
  • Application settings
    • AddressWhiteList
    • Bcc
    • and other applications

Usage

JavaDoc

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.


Sample

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 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 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() + ", " +
            "");
    }

Latest release

Download - 0.9.2

Maven

    <repositories>
        <repository>
            <id>jp.co.flect</id>
            <name>FLECT maven repository</name>
            <url>http://flect.github.io/maven-repo/</url>
        </repository>
    </repositories>

    <dependencies>
        <dependency>
            <groupId>jp.co.flect</groupId>
            <artifactId>sendgrid4j</artifactId>
            <version>0.9.2</version>
        </dependency>
    </dependencies>

License

MIT