Sipping from the SendGrid Java Library


September 09, 2013
Written by
SendGrid Team
Contributor
Opinions expressed by Twilio contributors are their own

Sipping from the SendGrid Java Library

sendgrid-javaThere's a new addition to the family of SendGrid libraries. Java developers can now use sendgrid-java, a module for sending emails through SendGrid using Java.

You've always been able to send emails through SendGrid using Java. You could use one of Java's built in SMTP libraries to communicate with our SMTP API or you could use an http request library to communicate with our Web API.

However, you had to write a fair amount of boilerplate code for both of these approaches. I recently had to build a Java application using SendGrid, and I was discouraged with this boilerplate code.

As I coded the application, I started pulling pieces out into a SendGrid.java file. This evolved into the SendGrid Java library you see today.

How to use it

To begin, add the library to your Java application. I recommend using gradle for this (detailed instructions here), but you can simply add the SendGrid.java file to your project if you prefer.

Then where you need, initiate the SendGrid object with your SendGrid credentials.

import com.github.sendgrid.SendGrid; SendGrid sendgrid = new SendGrid("sendgrid_username", "sendgrid_password");

Add your message details.

sendgrid.addTo("example@example.com"); sendgrid.addToName("Example Guy"); sendgrid.setFrom("other@example.com"); sendgrid.setSubject("Hello World"); sendgrid.setText("My first email through SendGrid");

And finally, send it.

sendgrid.send();

Enjoy! As of writing, the library is at version 0.1.0 and is stable. If you run into any bugs file them on the issues page.

Recommended For You



Most Popular


Send With Confidence

Partner with the email service trusted by developers and marketers for time-savings, scalability, and delivery expertise.