We recommend using SendGrid Java, our client library, available on GitHub, with full documentation.
Do you have an API Key yet? If not, go get one. You're going to need it to integrate!
_30// using SendGrid's Java Library_30// https://github.com/sendgrid/sendgrid-java_30import com.sendgrid.*;_30import com.sendgrid.helpers.mail.*;_30import com.sendgrid.helpers.mail.objects.*;_30import java.io.IOException;_30_30public class Example {_30 public static void main(String[] args) throws IOException {_30 Email from = new Email("[email protected]");_30 String subject = "Sending with SendGrid is Fun";_30 Email to = new Email("[email protected]");_30 Content content = new Content("text/plain", "and easy to do anywhere, even with Java");_30 Mail mail = new Mail(from, subject, to, content);_30_30 SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));_30 Request request = new Request();_30 try {_30 request.setMethod(Method.POST);_30 request.setEndpoint("mail/send");_30 request.setBody(mail.build());_30 Response response = sg.api(request);_30 System.out.println(response.getStatusCode());_30 System.out.println(response.getBody());_30 System.out.println(response.getHeaders());_30 } catch (IOException ex) {_30 throw ex;_30 }_30 }_30}