Skip to content

Commit 5b88db2

Browse files
Improve readme
1 parent c68b6e7 commit 5b88db2

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

README.md

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,10 @@ The following is the minimum needed code to send an email with the [/mail/send H
9999

100100
```java
101101
import com.sendgrid.*;
102-
import java.io.IOException;
102+
import com.sendgrid.helpers.mail.Mail;
103+
import com.sendgrid.helpers.mail.objects.Content;
104+
import com.sendgrid.helpers.mail.objects.Email;
105+
import com.sendgrid.helpers.mail.objects.Personalization;
103106

104107
public class Example {
105108
public static void main(String[] args) throws IOException {
@@ -126,6 +129,40 @@ public class Example {
126129
}
127130
```
128131

132+
or using fluence interface
133+
134+
```java
135+
import com.sendgrid.*;
136+
import com.sendgrid.helpers.mail.Mail;
137+
import com.sendgrid.helpers.mail.objects.Content;
138+
import com.sendgrid.helpers.mail.objects.Email;
139+
import com.sendgrid.helpers.mail.objects.Personalization;
140+
141+
public class Example {
142+
public static void main(String[] args) throws IOException {
143+
Mail mail = new Mail()
144+
.setFrom(new Email("[email protected]"))
145+
.setSubject("Hello World from the SendGrid Java Library!")
146+
.addPersonalization(new Personalization()
147+
.addTo(new Email("[email protected]")))
148+
.addContent(new Content("text/plain", "Hello, Email!"));
149+
SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
150+
Request request = new Request();
151+
try {
152+
request.method = Method.POST;
153+
request.endpoint = "mail/send";
154+
request.body = mail.build();
155+
Response response = sg.api(request);
156+
System.out.println(response.statusCode);
157+
System.out.println(response.body);
158+
System.out.println(response.headers);
159+
} catch (IOException ex) {
160+
throw ex;
161+
}
162+
}
163+
}
164+
```
165+
129166
The `Mail` constructor creates a [personalization object](https://sendgrid.com/docs/Classroom/Send/v3_Mail_Send/personalizations.html) for you. [Here](https://github.com/sendgrid/sendgrid-java/blob/master/examples/helpers/mail/Example.java#L221) is an example of how to add to it.
130167

131168
### Without Mail Helper Class

0 commit comments

Comments
 (0)