There'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.
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.
SendGrid sendgrid = new SendGrid("sendgrid_username", "sendgrid_password");
Add your message details.
sendgrid.setText("My first email through SendGrid");
And finally, send it.
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