This library allows you to quickly and easily use the SendGrid Web API via Java.
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.
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
Choose your installation method - Maven w/ Gradle (recommended), Maven or Jar file.
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;
mvn install
You can just drop the jar file in. It's a fat jar - it has all the dependencies built in.
import com.sendgrid.*;
- The SendGrid Service, starting at the free level
- Java-HTTP-Client
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;
}
}
}
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;
}
}
}
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.
We encourage contribution to our libraries, please see our CONTRIBUTING guide for details.
Quick links:
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)