Skip to content

Commit 8c4c157

Browse files
Merge pull request #132 from sendgrid/toc-template
Add Table of Contents to README and create USE_CASES section
2 parents 7dd02e9 + f19ba88 commit 8c4c157

File tree

2 files changed

+127
-0
lines changed

2 files changed

+127
-0
lines changed

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,19 @@ Please browse the rest of this README for further detail.
1010

1111
We appreciate your continued support, thank you!
1212

13+
# Table of Contents
14+
15+
* [Installation](#installation)
16+
* [Quick Start](#quick_start)
17+
* [Usage](#usage)
18+
* [Use Cases](#use_cases)
19+
* [Announcements](#announcements)
20+
* [Roadmap](#roadmap)
21+
* [How to Contribute](#contribute)
22+
* [Troubleshooting](#troubleshooting)
23+
* [About](#about)
24+
25+
<a name="installation"></a>
1326
# Installation
1427

1528
## Prerequisites
@@ -73,6 +86,7 @@ import com.sendgrid.*;
7386

7487
- [Java-HTTP-Client](https://github.com/sendgrid/java-http-client)
7588

89+
<a name="quick_start"></a>
7690
# Quick Start
7791

7892
## Hello Email
@@ -163,6 +177,7 @@ public class Example {
163177
}
164178
```
165179

180+
<a name="usage"></a>
166181
# Usage
167182

168183
- [SendGrid Docs](https://sendgrid.com/docs/API_Reference/Web_API_v3/index.html)
@@ -171,14 +186,23 @@ public class Example {
171186
- [How-to: Migration from v2 to v3](https://sendgrid.com/docs/Classroom/Send/v3_Mail_Send/how_to_migrate_from_v2_to_v3_mail_send.html)
172187
- [v3 Web API Mail Send Helper](https://github.com/sendgrid/sendgrid-java/tree/master/src/main/java/com/sendgrid/helpers) - build a request object payload for a v3 /mail/send API call.
173188

189+
190+
<a name="use_cases">
191+
# Use Cases
192+
193+
[Examples of common API use cases](https://github.com/sendgrid/sendgrid-java/blob/master/USE_CASES.md), such as how to send an email with a transactional template.
194+
195+
<a name="announcements"></a>
174196
# Announcements
175197

176198
All updates to this library is documented in our [CHANGELOG](https://github.com/sendgrid/sendgrid-java/blob/master/CHANGELOG.md) and [releases](https://github.com/sendgrid/sendgrid-java/releases).
177199

200+
<a name="roadmap"></a>
178201
# Roadmap
179202

180203
If you are interested in the future direction of this project, please take a look at our open [issues](https://github.com/sendgrid/sendgrid-java/issues) and [pull requests](https://github.com/sendgrid/sendgrid-java/pulls). We would love to hear your feedback.
181204

205+
<a name="contribute"></a>
182206
# How to Contribute
183207

184208
We encourage contribution to our libraries (you might even score some nifty swag), please see our [CONTRIBUTING](https://github.com/sendgrid/sendgrid-java/blob/master/CONTRIBUTING.md) guide for details.
@@ -190,10 +214,12 @@ Quick links:
190214
- [Sign the CLA to Create a Pull Request](https://github.com/sendgrid/sendgrid-java/blob/master/CONTRIBUTING.md#cla)
191215
- [Improvements to the Codebase](https://github.com/sendgrid/sendgrid-java/blob/master/CONTRIBUTING.md#improvements_to_the_codebase)
192216

217+
<a name="troubleshooting"></a>
193218
# Troubleshooting
194219

195220
Please see our [troubleshooting guide](https://github.com/sendgrid/sendgrid-java/blob/master/TROUBLESHOOTING.md) for common library issues.
196221

222+
<a name="about"></a>
197223
# About
198224

199225
sendgrid-java is guided and supported by the SendGrid [Developer Experience Team](mailto:[email protected]).

USE_CASES.md

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
This documentation provides examples for specific use cases. Please [open an issue](https://github.com/sendgrid/sendgrid-java/issues) or make a pull request for any use cases you would like us to document here. Thank you!
2+
3+
# Table of Contents
4+
5+
* [Transactional Templates](#transactional_templates)
6+
7+
<a name="transactional_templates"></a>
8+
# Transactional Templates
9+
10+
For this example, we assume you have created a [transactional template](https://sendgrid.com/docs/User_Guide/Transactional_Templates/index.html). Following is the template content we used for testing.
11+
12+
Template ID (replace with your own):
13+
14+
```text
15+
13b8f94f-bcae-4ec6-b752-70d6cb59f932
16+
```
17+
18+
Email Subject:
19+
20+
```text
21+
<%subject%>
22+
```
23+
24+
Template Body:
25+
26+
```html
27+
<html>
28+
<head>
29+
<title></title>
30+
</head>
31+
<body>
32+
Hello -name-,
33+
<br /><br/>
34+
I'm glad you are trying out the template feature!
35+
<br /><br/>
36+
<%body%>
37+
<br /><br/>
38+
I hope you are having a great day in -city- :)
39+
<br /><br/>
40+
</body>
41+
</html>
42+
```
43+
44+
## With Mail Helper Class
45+
46+
```java
47+
import com.sendgrid.*;
48+
import java.io.IOException;
49+
50+
public class Example {
51+
public static void main(String[] args) throws IOException {
52+
Email from = new Email("[email protected]");
53+
String subject = "I'm replacing the subject tag";
54+
Email to = new Email("[email protected]");
55+
Content content = new Content("text/html", "I'm replacing the <strong>body tag</strong>");
56+
Mail mail = new Mail(from, subject, to, content);
57+
mail.personalization.get(0).addSubstitution("-name-", "Example User");
58+
mail.personalization.get(0).addSubstitution("-city-", "Denver");
59+
mail.setTemplateId("13b8f94f-bcae-4ec6-b752-70d6cb59f932");
60+
61+
SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
62+
Request request = new Request();
63+
try {
64+
request.method = Method.POST;
65+
request.endpoint = "mail/send";
66+
request.body = mail.build();
67+
Response response = sg.api(request);
68+
System.out.println(response.statusCode);
69+
System.out.println(response.body);
70+
System.out.println(response.headers);
71+
} catch (IOException ex) {
72+
throw ex;
73+
}
74+
}
75+
}
76+
```
77+
78+
## Without Mail Helper Class
79+
80+
```java
81+
import com.sendgrid.*;
82+
import java.io.IOException;
83+
84+
public class Example {
85+
public static void main(String[] args) throws IOException {
86+
try {
87+
SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
88+
Request request = new Request();
89+
request.method = Method.POST;
90+
request.endpoint = "mail/send";
91+
request.body = "{\"personalizations\":[{\"to\":[{\"email\":\"[email protected]\"}],\"substitutions\":{\"-name-\":\"Example User\",\"-city-\":\"Denver\"},\"subject\":\"Hello World from the SendGrid Java Library!\"}],\"from\":{\"email\":\"[email protected]\"},\"content\":[{\"type\":\"text/html\",\"value\": \"I'm replacing the <strong>body tag</strong>\"}],\"template_id\": \"13b8f94f-bcae-4ec6-b752-70d6cb59f932\"}";
92+
Response response = sg.api(request);
93+
System.out.println(response.statusCode);
94+
System.out.println(response.body);
95+
System.out.println(response.headers);
96+
} catch (IOException ex) {
97+
throw ex;
98+
}
99+
}
100+
}
101+
```

0 commit comments

Comments
 (0)