We will deprecate this version on February 10, 2025. To access all the latest features and upcoming developments, please see our v3 API. For assistance with transitioning, refer to our migration guide.
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.
1// using SendGrid's Java Library2// https://github.com/sendgrid/sendgrid-java3import com.sendgrid.*;45public class SendGridExample {6public static void main(String[] args) {7SendGrid sendgrid = new SendGrid("SENDGRID_APIKEY");89SendGrid.Email email = new SendGrid.Email();1011email.addTo("test@sendgrid.com");12email.setFrom("you@youremail.com");13email.setSubject("Sending with SendGrid is Fun");14email.setHtml("and easy to do anywhere, even with Java");1516SendGrid.Response response = sendgrid.send(email);17}18}