diff --git a/src/groovy/uk/co/desirableobjects/sendgrid/SendGridEmail.groovy b/src/groovy/uk/co/desirableobjects/sendgrid/SendGridEmail.groovy index 29c780d..9102997 100644 --- a/src/groovy/uk/co/desirableobjects/sendgrid/SendGridEmail.groovy +++ b/src/groovy/uk/co/desirableobjects/sendgrid/SendGridEmail.groovy @@ -22,6 +22,7 @@ class SendGridEmail { Map headers = [:] Map customHandlingInstructions = [:] Map attachments = [:] + Map contentIdForAttachments = [:] private allParameters = [ username: 'api_user', @@ -46,6 +47,7 @@ class SendGridEmail { parameters.putAll(encodeParameters()) parameters.putAll(addAttachments()) + parameters.putAll(addContentIdForAttachments()) return parameters @@ -76,6 +78,16 @@ class SendGridEmail { return parameters } + private Map addContentIdForAttachments() { + Map parameters = [:] + + contentIdForAttachments.each { String filename, String contentId -> + parameters.put("content[${filename}]" as String, contentId) + } + + return parameters + } + private List map(List values) { return values } diff --git a/src/groovy/uk/co/desirableobjects/sendgrid/SendGridEmailBuilder.groovy b/src/groovy/uk/co/desirableobjects/sendgrid/SendGridEmailBuilder.groovy index 0365206..c9460b2 100644 --- a/src/groovy/uk/co/desirableobjects/sendgrid/SendGridEmailBuilder.groovy +++ b/src/groovy/uk/co/desirableobjects/sendgrid/SendGridEmailBuilder.groovy @@ -85,6 +85,13 @@ class SendGridEmailBuilder { return this } + SendGridEmailBuilder addAttachment(String filename, String contentId, File file) { + + addAttachment(filename, file) + email.contentIdForAttachments.put(filename, contentId) + return this + } + SendGridEmail build() { validateRequiredParameters() return this.email diff --git a/src/groovy/uk/co/desirableobjects/sendgrid/SendGridSendMailDSLDelegate.groovy b/src/groovy/uk/co/desirableobjects/sendgrid/SendGridSendMailDSLDelegate.groovy index 1bedf3b..80acaf4 100644 --- a/src/groovy/uk/co/desirableobjects/sendgrid/SendGridSendMailDSLDelegate.groovy +++ b/src/groovy/uk/co/desirableobjects/sendgrid/SendGridSendMailDSLDelegate.groovy @@ -38,4 +38,8 @@ class SendGridSendMailDSLDelegate { return builder.addAttachment(filename, attachment) } + SendGridEmailBuilder attach(String filename, String contentId, File attachment) { + return builder.addAttachment(filename, contentId, attachment) + } + }