File tree Expand file tree Collapse file tree 4 files changed +37
-0
lines changed Expand file tree Collapse file tree 4 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -354,6 +354,14 @@ email.setASMGroupId(1);
354
354
email. setSendAt(1409348513 );
355
355
```
356
356
357
+ ### [ Templates] ( https://sendgrid.com/docs/API_Reference/Web_API_v3/Template_Engine/index.html )
358
+
359
+ #### setTemplateId
360
+
361
+ ``` java
362
+ email. setTemplateId(" abc123-def456" );
363
+ ```
364
+
357
365
## Contributing
358
366
359
367
1 . Fork it
Original file line number Diff line number Diff line change @@ -51,6 +51,7 @@ dependencies {
51
51
compile ' org.apache.httpcomponents:httpmime:4.3.4'
52
52
compile ' org.json:json:20140107'
53
53
testCompile group : ' junit' , name : ' junit' , version : ' 4.12'
54
+ testCompile group : ' org.skyscreamer' , name : ' jsonassert' , version : ' 1.2.3'
54
55
}
55
56
56
57
repositories {
Original file line number Diff line number Diff line change @@ -396,6 +396,16 @@ public int getSendAt() {
396
396
return this .smtpapi .getSendAt ();
397
397
}
398
398
399
+ /**
400
+ * Convenience method to set the template
401
+ * @param templateId
402
+ */
403
+ public Email setTemplateId (String templateId ) {
404
+ this .getSMTPAPI ().addFilter ("templates" , "enable" , 1 );
405
+ this .getSMTPAPI ().addFilter ("templates" , "template_id" , templateId );
406
+ return this ;
407
+ }
408
+
399
409
public Email addAttachment (String name , File file ) throws IOException , FileNotFoundException {
400
410
return this .addAttachment (name , new FileInputStream (file ));
401
411
}
Original file line number Diff line number Diff line change 3
3
import java .util .HashMap ;
4
4
import java .util .Map ;
5
5
6
+ import org .skyscreamer .jsonassert .JSONAssert ;
7
+
8
+ import org .json .JSONObject ;
6
9
import org .junit .Test ;
7
10
8
11
import static org .junit .Assert .*;
@@ -159,6 +162,21 @@ public void testAddHeader() {
159
162
assertEquals (correct , email .getHeaders ());
160
163
}
161
164
165
+ @ Test
166
+ public void testSetTemplateId () {
167
+ email = new SendGrid .Email ();
168
+ email .setTemplateId ("abc-123" );
169
+
170
+ String filters = email .getSMTPAPI ().jsonString ();
171
+
172
+ JSONObject obj = new JSONObject ();
173
+ obj .put ("filters" , new JSONObject ().put ("templates" , new JSONObject ()
174
+ .put ("settings" , new JSONObject ().put ("enable" , 1 )
175
+ .put ("template_id" , "abc-123" ))));
176
+
177
+ JSONAssert .assertEquals (filters , obj .toString (), false );
178
+ }
179
+
162
180
@ Test
163
181
public void testSmtpapiToHeader () {
164
182
email = new SendGrid .Email ();
You can’t perform that action at this time.
0 commit comments