Skip to content

Commit c2dc72b

Browse files
author
elbuo8
committed
Added CID support
1 parent 1841097 commit c2dc72b

2 files changed

Lines changed: 24 additions & 4 deletions

File tree

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ apply plugin: 'maven'
1717
apply plugin: 'signing'
1818

1919
group = 'com.sendgrid'
20-
version = "1.2.1"
20+
version = "1.3.0"
2121
ext.packaging = 'jar'
2222

2323
allprojects {

src/main/java/com/sendgrid/SendGrid.java

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import org.apache.http.entity.ContentType;
2929

3030
public 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

Comments
 (0)