Skip to contentSkip to navigationSkip to topbar
Rate this page:
On this page

v2 API Java Code Example


(information)

Info

We recommend using SendGrid Java, our client library, available on GitHub(link takes you to an external page), with full documentation.

(information)

Info

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(link takes you to an external page).


Using SendGrid's Java Library

using-sendgrids-java-library page anchor

_18
// using SendGrid's Java Library
_18
// https://github.com/sendgrid/sendgrid-java
_18
import com.sendgrid.*;
_18
_18
public class SendGridExample {
_18
public static void main(String[] args) {
_18
SendGrid sendgrid = new SendGrid("SENDGRID_APIKEY");
_18
_18
SendGrid.Email email = new SendGrid.Email();
_18
_18
email.addTo("test@sendgrid.com");
_18
email.setFrom("you@youremail.com");
_18
email.setSubject("Sending with SendGrid is Fun");
_18
email.setHtml("and easy to do anywhere, even with Java");
_18
_18
SendGrid.Response response = sendgrid.send(email);
_18
}
_18
}


Rate this page: