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
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("email@example.com"); sendgrid.addToName("Example Guy"); sendgrid.setFrom("firstname.lastname@example.org"); sendgrid.setSubject("Hello World"); sendgrid.setText("My first email through SendGrid");
And finally, send it.