v2 API Java Code Example
We recommend using SendGrid Java, our client library, available on GitHub, with full documentation.
The library does not officially support the V2 API, but you can use V2 with an older version of the library. For more information, see Continue Using V2 in Java.
Using SendGrid's Java Library
// using SendGrid's Java Library
// https://github.com/sendgrid/sendgrid-java
import com.sendgrid.*;
public class SendGridExample {
public static void main(String[] args) {
SendGrid sendgrid = new SendGrid("SENDGRID_APIKEY");
SendGrid.Email email = new SendGrid.Email();
email.addTo("test@sendgrid.com");
email.setFrom("you@youremail.com");
email.setSubject("Sending with SendGrid is Fun");
email.setHtml("and easy to do anywhere, even with Java");
SendGrid.Response response = sendgrid.send(email);
}
}
Need some help?
We all do sometimes. Get help now from the Twilio SendGrid Support Team.
Running into a coding hurdle? Lean on the wisdom of the crowd by browsing the SendGrid tag on Stack Overflow or visiting Twilio's Stack Overflow Collective.