File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -5,21 +5,30 @@ This Java module allows you to quickly and easily send emails through SendGrid u
55[ ![ BuildStatus] ( https://travis-ci.org/sendgrid/sendgrid-java.png?branch=master )] ( https://travis-ci.org/sendgrid/sendgrid-java )
66
77``` java
8+ // SendGridExample.java
89import com.sendgrid.* ;
9- SendGrid sendgrid = new SendGrid (" sendgrid_username" , " sendgrid_password" );
10-
11- SendGrid . Email email = new SendGrid .Email ();
12- email. addTo(" example@example.com" );
13- email. setFrom(" other@example.com" );
14- email. setSubject(" Hello World" );
15- email. setText(" My first email through SendGrid" );
1610
17- try {
18- SendGrid . Response response = sendgrid. send(email);
19- catch (SendGridException e) {
20- System . out. println(e);
11+ public class SendGridExample {
12+ public static void main (String [] args ) {
13+ SendGrid sendgrid = new SendGrid (System . getenv(" SENDGRID_USERNAME" ), System . getenv(" SENDGRID_PASSWORD" ));
14+
15+ SendGrid . Email email = new SendGrid .Email ();
16+ email. addTo(" example@example.com" );
17+ email. setFrom(" other@example.com" );
18+ email. setSubject(" Hello World" );
19+ email. setText(" My first email with SendGrid Java!" );
20+
21+ try {
22+ SendGrid . Response response = sendgrid. send(email);
23+ System . out. println(response. getMessage());
24+ }
25+ catch (SendGridException e) {
26+ System . err. println(e);
27+ }
28+ }
2129}
2230```
31+ Compile and run this example with ` javac -classpath sendgrid-1.2.0-jar.jar:. SendGridExample.java && java -classpath sendgrid-1.2.0-jar.jar:. SendGridExample `
2332
2433## Installation
2534
You can’t perform that action at this time.
0 commit comments