Skip to content
This repository has been archived by the owner on Jul 28, 2023. It is now read-only.

Commit

Permalink
Merge pull request #78 from agorapulse/feature/send-template-multiple…
Browse files Browse the repository at this point in the history
…-recepients

send template to multiple recipients - fixes #77
  • Loading branch information
musketyr authored Sep 18, 2018
2 parents dc1fffb + c2cecc0 commit 070931d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version=2.2.4
version=2.2.5
awsJavaSdkVersion=1.11.375
awsKinesisClientVersion=1.8.5
gradleWrapperVersion=3.4.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class AmazonSESTemplateService extends AmazonSESService {
* @param replyToEmail
* @return 1 if successful, 0 if not sent, -1 if blacklisted
*/
int sendTemplate(String destinationEmail,
int sendTemplate(List<String> destinationEmails,
String subjectKey,
List subjectVariables,
Map model,
Expand All @@ -68,14 +68,39 @@ class AmazonSESTemplateService extends AmazonSESService {
String replyToEmail = '',
String defaultSubject = '') {
int statusId = 0
if (destinationEmail != '') {
String htmlBody = renderHtmlForTemplate(locale, model, destinationEmail, templateName, timeZoneGmt)
if (destinationEmails.findAll()) {
String htmlBody = renderHtmlForTemplate(locale, model, destinationEmails, templateName, timeZoneGmt)
String subject = subjectWithSubjectKey(subjectKey, subjectVariables, locale, defaultSubject)
statusId = send(destinationEmail, subject, htmlBody, '', replyToEmail)
statusId = send(destinationEmails, subject, htmlBody, '', replyToEmail)
}
statusId
}

/**
* Global method to send email to anybody
*
* @param destinationEmail
* @param subjectKey
* @param subjectVariables
* @param model
* @param templateName
* @param locale
* @param timeZoneGmt
* @param replyToEmail
* @return 1 if successful, 0 if not sent, -1 if blacklisted
*/
int sendTemplate(String destinationEmail,
String subjectKey,
List subjectVariables,
Map model,
String templateName,
Locale locale = Locale.ENGLISH,
int timeZoneGmt = 0,
String replyToEmail = '',
String defaultSubject = '') {
return sendTemplate(Collections.singletonList(destinationEmail), subjectKey, subjectVariables, model, templateName, locale, timeZoneGmt, replyToEmail, defaultSubject)
}

private String subjectWithSubjectKey(String subjectKey, List subjectVariables, Locale locale = Locale.ENGLISH, String defaultSubject = '') {
try {
return messageSource.getMessage(subjectKey, subjectVariables as Object[], locale)
Expand All @@ -86,12 +111,13 @@ class AmazonSESTemplateService extends AmazonSESService {
}
}

String renderHtmlForTemplate(Locale locale, Map model, String destinationEmail, String templateName, int timeZoneGmt = 0) {
String renderHtmlForTemplate(Locale locale, Map model, List<String> destinationEmails, String templateName, int timeZoneGmt = 0) {
def t = "${templatePath}/${templateName}" as String
groovyPageRenderer.render(
model: model + [
locale : locale,
notificationEmail: destinationEmail,
notificationEmail: destinationEmails.first(),
destinationEmails: destinationEmails,
sentDate: new LocalDateTime().plusMinutes((timeZoneGmt * 60).toInteger()).toDate()
],
template: t
Expand Down

0 comments on commit 070931d

Please sign in to comment.