2828import org .apache .http .entity .ContentType ;
2929
3030public class SendGrid {
31- private static final String VERSION = "1.2.1 " ;
31+ private static final String VERSION = "1.3.0 " ;
3232 private static final String USER_AGENT = "sendgrid/" + VERSION + ";java" ;
3333
3434 private static final String PARAM_TO = "to[%d]" ;
@@ -42,6 +42,7 @@ public class SendGrid {
4242 private static final String PARAM_HTML = "html" ;
4343 private static final String PARAM_TEXT = "text" ;
4444 private static final String PARAM_FILES = "files[%s]" ;
45+ private static final String PARAM_CONTENTS = "content[%s]" ;
4546 private static final String PARAM_XSMTPAPI = "x-smtpapi" ;
4647 private static final String PARAM_HEADERS = "headers" ;
4748
@@ -107,6 +108,14 @@ public HttpEntity buildBody(Email email) {
107108 }
108109 }
109110
111+ if (email .getContentIds ().size () > 0 ) {
112+ Iterator it = email .getContentIds ().entrySet ().iterator ();
113+ while (it .hasNext ()) {
114+ Map .Entry entry = (Map .Entry ) it .next ();
115+ builder .addTextBody (String .format (PARAM_CONTENTS , entry .getKey ()), (String ) entry .getValue ());
116+ }
117+ }
118+
110119 if (email .getHeaders ().size () > 0 )
111120 builder .addTextBody (PARAM_HEADERS , new JSONObject (email .getHeaders ()).toString ());
112121
@@ -159,6 +168,7 @@ public static class Email {
159168 private String html ;
160169 private ArrayList <String > bcc ;
161170 private Map <String , InputStream > attachments ;
171+ private Map <String , String > contents ;
162172 private Map <String , String > headers ;
163173
164174 public Email () {
@@ -168,8 +178,9 @@ public Email () {
168178 this .cc = new ArrayList <String >();
169179 this .bcc = new ArrayList <String >();
170180 this .attachments = new HashMap <String , InputStream >();
171- this .headers = new HashMap <String , String >();
172- }
181+ this .contents = new HashMap <String , String >();
182+ this .headers = new HashMap <String , String >();
183+ }
173184
174185 public Email addTo (String to ) {
175186 this .smtpapi .addTo (to );
@@ -378,6 +389,15 @@ public Map getAttachments() {
378389 return this .attachments ;
379390 }
380391
392+ public Email addContentId (String attachmentName , String cid ) {
393+ this .contents .put (attachmentName , cid );
394+ return this ;
395+ }
396+
397+ public Map getContentIds () {
398+ return this .contents ;
399+ }
400+
381401 public Email addHeader (String key , String val ) {
382402 this .headers .put (key , val );
383403 return this ;
0 commit comments