Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/groovy/uk/co/desirableobjects/sendgrid/SendGridEmail.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class SendGridEmail {
Map headers = [:]
Map customHandlingInstructions = [:]
Map<String, File> attachments = [:]
Map<String, String> contentIdForAttachments = [:]

private allParameters = [
username: 'api_user',
Expand All @@ -46,6 +47,7 @@ class SendGridEmail {

parameters.putAll(encodeParameters())
parameters.putAll(addAttachments())
parameters.putAll(addContentIdForAttachments())

return parameters

Expand Down Expand Up @@ -76,6 +78,16 @@ class SendGridEmail {
return parameters
}

private Map<String, Object> addContentIdForAttachments() {
Map<String, Object> parameters = [:]

contentIdForAttachments.each { String filename, String contentId ->
parameters.put("content[${filename}]" as String, contentId)
}

return parameters
}

private List<String> map(List<String> values) {
return values
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

}