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);
354354email. setSendAt(1409348513 );
355355```
356356
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+
357365## Contributing
358366
3593671 . Fork it
Original file line number Diff line number Diff line change @@ -51,6 +51,7 @@ dependencies {
5151 compile ' org.apache.httpcomponents:httpmime:4.3.4'
5252 compile ' org.json:json:20140107'
5353 testCompile group : ' junit' , name : ' junit' , version : ' 4.12'
54+ testCompile group : ' org.skyscreamer' , name : ' jsonassert' , version : ' 1.2.3'
5455}
5556
5657repositories {
Original file line number Diff line number Diff line change @@ -396,6 +396,16 @@ public int getSendAt() {
396396 return this .smtpapi .getSendAt ();
397397 }
398398
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+
399409 public Email addAttachment (String name , File file ) throws IOException , FileNotFoundException {
400410 return this .addAttachment (name , new FileInputStream (file ));
401411 }
Original file line number Diff line number Diff line change 33import java .util .HashMap ;
44import java .util .Map ;
55
6+ import org .skyscreamer .jsonassert .JSONAssert ;
7+
8+ import org .json .JSONObject ;
69import org .junit .Test ;
710
811import static org .junit .Assert .*;
@@ -159,6 +162,21 @@ public void testAddHeader() {
159162 assertEquals (correct , email .getHeaders ());
160163 }
161164
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+
162180 @ Test
163181 public void testSmtpapiToHeader () {
164182 email = new SendGrid .Email ();
You can’t perform that action at this time.
0 commit comments