Skip to content

PrinceWang80/sendgrid-java

 
 

Repository files navigation

Travis Badge BuildStatus

This library allows you to quickly and easily use the SendGrid Web API via Java.

Announcements

BREAKING CHANGE as of 2016.06.14

Version 3.X.X is a breaking change for the entire library.

Version 3.X.X brings you full support for all Web API v3 endpoints. We have the following resources to get you started quickly:

Thank you for your continued support!

All updates to this library is documented in our CHANGELOG.

Installation

Setup Environment Variables

First, get your free SendGrid account here.

Next, update your environment with your SENDGRID_API_KEY.

echo "export SENDGRID_API_KEY='YOUR_API_KEY'" > sendgrid.env
echo "sendgrid.env" >> .gitignore
source ./sendgrid.env

Install Package

Choose your installation method - Maven w/ Gradle (recommended), Maven or Jar file.

via Maven w/ Gradle

Add the following to your build.gradle file in the root of your project.

...
dependencies {
  ...
  compile 'com.sendgrid:sendgrid-java:3.0.2'
}

repositories {
  mavenCentral()
}
...

Then import the library - in the file appropriate to your Java project.

import com.sendgrid.SendGrid;

via Maven

mvn install

via jar file

You can just drop the jar file in. It's a fat jar - it has all the dependencies built in.

sendgrid-java.jar

import com.sendgrid.*;

Dependencies

Quick Start

Hello Email

import com.sendgrid.*;
import java.io.IOException;

public class Example {
  public static void main(String[] args) throws IOException {
    Email from = new Email("[email protected]");
    String subject = "Hello World from the SendGrid Java Library";
    Email to = new Email("[email protected]");
    Content content = new Content("text/plain", "some text here");
    Mail mail = new Mail(from, subject, to, content);

    SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
    Request request = new Request();
    try {
      request.method = Method.POST;
      request.endpoint = "mail/send";
      request.body = mail.build();
      Response response = sg.api(request);
      System.out.println(response.statusCode);
      System.out.println(response.body);
      System.out.println(response.headers);
    } catch (IOException ex) {
      throw ex;
    }
  }
}

General v3 Web API Usage

import com.sendgrid.*;
import java.io.IOException;

public class Example {
  public static void main(String[] args) throws IOException {
    SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
    try {
      Request request = new Request();
      request.method = Method.GET;
      request.endpoint = "api_keys";
      Response response = sg.api(request);
      System.out.println(response.statusCode);
      System.out.println(response.body);
      System.out.println(response.headers);
    } catch (IOException ex) {
      throw ex;
    }
  }
}

Usage

Roadmap

If you are intersted in the future direction of this project, please take a look at our milestones. We would love to hear your feedback.

How to Contribute

We encourage contribution to our libraries, please see our CONTRIBUTING guide for details.

Quick links:

About

sendgrid-java is guided and supported by the SendGrid Developer Experience Team.

sendgrid-java is maintained and funded by SendGrid, Inc. The names and logos for sendgrid-java are trademarks of SendGrid, Inc.

![SendGrid Logo] (https://uiux.s3.amazonaws.com/2016-logos/email-logo%402x.png)

About

SendGrid Java helper library

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 98.9%
  • Other 1.1%