Skip to content

Commit

Permalink
Merge pull request #175 from agorapulse/feature/allow-adding-configur…
Browse files Browse the repository at this point in the history
…ation-set-on-emails

Allow adding configuration set on emails
  • Loading branch information
DKarim authored Aug 28, 2023
2 parents b21315d + 5651914 commit 569a951
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 38 deletions.
26 changes: 14 additions & 12 deletions docs/guide/src/docs/asciidoc/ses.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,13 @@ include::{root-dir}/subprojects/micronaut-amazon-awssdk-ses/src/test/groovy/com/
<3> Define the from address
<4> Define one or more recipients
<5> Define HTML body (alternatively you can declare plain text body as well)
<6> Define tags for the email, they will be included in SES events
<7> Build an attachment
<8> Define the location of the file to be sent
<9> Define the file name (optional - deduced from the file)
<10> Define the mime type (usually optional - deduced from the file)
<11> Define the description of the file (optional)
<6> Define configuration set for the email (https://docs.aws.amazon.com/ses/latest/dg/using-configuration-sets.html)
<7> Define tags for the email, they will be included in SES events
<8> Build an attachment
<9> Define the location of the file to be sent
<10> Define the file name (optional - deduced from the file)
<11> Define the mime type (usually optional - deduced from the file)
<12> Define the description of the file (optional)


[source,java,indent=0,options="nowrap",role="secondary"]
Expand All @@ -73,12 +74,13 @@ include::{root-dir}/subprojects/micronaut-amazon-awssdk-ses/src/test/groovy/com/
<3> Define the from address
<4> Define one or more recipients
<5> Define HTML body (alternatively you can declare plain text body as well)
<6> Define tags for the email, they will be included in SES events
<7> Build an attachment
<8> Define the location of the file to be sent
<9> Define the file name (optional - deduced from the file)
<10> Define the mime type (usually optional - deduced from the file)
<11> Define the description of the file (optional)
<6> Define configuration set for the email (https://docs.aws.amazon.com/ses/latest/dg/using-configuration-sets.html)
<7> Define tags for the email, they will be included in SES events
<8> Build an attachment
<9> Define the location of the file to be sent
<10> Define the file name (optional - deduced from the file)
<11> Define the mime type (usually optional - deduced from the file)
<12> Define the description of the file (optional)

Please, see
https://agorapulse.github.io/micronaut-aws-sdk/api/com/agorapulse/micronaut/amazon/awsses/SimpleEmailService.html[SimpleEmailService AWS SDK 2.x]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class TransactionalEmail {
private String subject = "";
private String htmlBody = "<html><body></body></html>";
private String replyTo = "";
private String configurationSetName = "";
private Map<String, String> tags = new HashMap<>();

private final List<String> recipients = new ArrayList<>();
Expand Down Expand Up @@ -79,6 +80,11 @@ public TransactionalEmail replyTo(String str) {
return this;
}

public TransactionalEmail configurationSetName(String str) {
this.configurationSetName = str;
return this;
}

public TransactionalEmail tags(Map<String, String> customTags) {
this.tags = customTags;
return this;
Expand Down Expand Up @@ -108,6 +114,10 @@ public List<TransactionalEmailAttachment> getAttachments() {
return Collections.unmodifiableList(attachments);
}

public String getConfigurationSetName() {
return configurationSetName;
}

public Map<String, String> getTags() {
return tags;
}
Expand All @@ -122,6 +132,7 @@ public String toString() {
", replyTo='" + replyTo + '\'' +
", recipients=" + recipients +
", attachments=" + attachments +
", configurationSetName=" + configurationSetName +
", tags=" + tags +
'}';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,13 @@ class SendEmailSpec extends Specification {
from '[email protected]' // <3>
to '[email protected]' // <4>
htmlBody '<p>This is an example body</p>' // <5>
tags mapOfTags // <6>
attachment { // <7>
filepath thePath // <8>
filename 'test.pdf' // <9>
mimeType 'application/pdf' // <10>
description 'An example pdf' // <11>
configurationSetName 'configuration-set' // <6>
tags mapOfTags // <7>
attachment { // <8>
filepath thePath // <9>
filename 'test.pdf' // <10>
mimeType 'application/pdf' // <11>
description 'An example pdf' // <12>
}
}
// end::builder[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,13 @@ public void testSendEmail() throws IOException {
.from("[email protected]") // <3>
.to("[email protected]") // <4>
.htmlBody("<p>This is an example body</p>") // <5>
.tags(mapOfTags) // <6>
.attachment(a -> // <7>
a.filepath(filepath) // <8>
.filename("test.pdf") // <9>
.mimeType("application/pdf") // <10>
.description("An example pdf") // <11>
.configurationSetName("configuration-set") // <6>
.tags(mapOfTags) // <7>
.attachment(a -> // <8>
a.filepath(filepath) // <9>
.filename("test.pdf") // <10>
.mimeType("application/pdf") // <11>
.description("An example pdf") // <12>
)
);
// end::builder[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import spock.lang.Subject
/**
* Tests for simple email service.
*/
@SuppressWarnings(['AbcMetric', 'JavaIoPackageAccess'])
@SuppressWarnings(['AbcMetric', 'JavaIoPackageAccess', 'UnnecessaryObjectReferences'])
class SimpleEmailServiceSpec extends Specification {

SesClient simpleEmailService = Mock(SesClient)
Expand All @@ -52,6 +52,7 @@ class SimpleEmailServiceSpec extends Specification {
from '[email protected]'
to '[email protected]'
htmlBody '<p>This is an example body</p>'
configurationSetName 'configuration-set'
tags customTags
attachment {
filename 'test.pdf'
Expand All @@ -67,6 +68,7 @@ class SimpleEmailServiceSpec extends Specification {
transactionalEmail.htmlBody == '<p>This is an example body</p>'
transactionalEmail.from == '[email protected]'
transactionalEmail.recipients == ['[email protected]']
transactionalEmail.configurationSetName == 'configuration-set'
transactionalEmail.tags == [key1: 'value1', key2: 'value2']
transactionalEmail.attachments.size() == 1
transactionalEmail.attachments.first().filename == 'test.pdf'
Expand All @@ -86,6 +88,7 @@ class SimpleEmailServiceSpec extends Specification {
htmlBody '<p>This is an example body</p>'
to '[email protected]'
from '[email protected]'
configurationSetName 'configuration-set'
tags customTags
attachment {
filepath f.absolutePath
Expand All @@ -98,6 +101,7 @@ class SimpleEmailServiceSpec extends Specification {
transactionalEmail.htmlBody == '<p>This is an example body</p>'
transactionalEmail.from == '[email protected]'
transactionalEmail.recipients == ['[email protected]']
transactionalEmail.configurationSetName == 'configuration-set'
transactionalEmail.tags == [key1: 'value1', key2: 'value2']
transactionalEmail.attachments.size() == 1
transactionalEmail.attachments.first().filename == 'groovylogo.png'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ class DefaultSimpleEmailService implements SimpleEmailService {
rawEmailRequest.destinations = email.recipients
rawEmailRequest.source = email.from ?: configuration.sourceEmail.orElse(null)
rawEmailRequest.tags = getTags(email)
rawEmailRequest.configurationSetName = email.configurationSetName

return handleSend(email) {
client.sendRawEmail(rawEmailRequest)
Expand Down Expand Up @@ -185,6 +186,7 @@ class DefaultSimpleEmailService implements SimpleEmailService {
if (email.replyTo) {
sendEmailRequest.replyToAddresses = singletonList(email.replyTo)
}
sendEmailRequest.configurationSetName = email.configurationSetName
sendEmailRequest.tags = getTags(email)
client.sendEmail(sendEmailRequest)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class TransactionalEmail {
private String subject = "";
private String htmlBody = "<html><body></body></html>";
private String replyTo = "";
private String configurationSetName = "";
private Map<String, String> tags = new HashMap<>();

private final List<String> recipients = new ArrayList<>();
Expand Down Expand Up @@ -86,6 +87,11 @@ public TransactionalEmail replyTo(String str) {
return this;
}

public TransactionalEmail configurationSetName(String str) {
this.configurationSetName = str;
return this;
}

public TransactionalEmail tags(Map<String, String> customTags) {
this.tags = customTags;
return this;
Expand Down Expand Up @@ -115,6 +121,10 @@ public List<TransactionalEmailAttachment> getAttachments() {
return attachments;
}

public String getConfigurationSetName() {
return configurationSetName;
}

public Map<String, String> getTags() {
return tags;
}
Expand All @@ -129,6 +139,7 @@ public String toString() {
", replyTo='" + replyTo + '\'' +
", recipients=" + recipients +
", attachments=" + attachments +
", configurationSetName=" + configurationSetName +
", tags=" + tags +
'}';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,13 @@ class SendEmailSpec extends Specification {
from '[email protected]' // <3>
to '[email protected]' // <4>
htmlBody '<p>This is an example body</p>' // <5>
tags mapOfTags // <6>
attachment { // <7>
filepath thePath // <8>
filename 'test.pdf' // <9>
mimeType 'application/pdf' // <10>
description 'An example pdf' // <11>
configurationSetName 'configuration-set' // <6>
tags mapOfTags // <7>
attachment { // <8>
filepath thePath // <9>
filename 'test.pdf' // <10>
mimeType 'application/pdf' // <11>
description 'An example pdf' // <12>
}
}
// end::builder[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,13 @@ public void testSendEmail() throws IOException {
.from("[email protected]") // <3>
.to("[email protected]") // <4>
.htmlBody("<p>This is an example body</p>") // <5>
.tags(mapOfTags) // <6>
.attachment(a -> // <7>
a.filepath(filepath) // <8>
.filename("test.pdf") // <9>
.mimeType("application/pdf") // <10>
.description("An example pdf") // <11>
.configurationSetName("configuration-set") // <6>
.tags(mapOfTags) // <7>
.attachment(a -> // <8>
a.filepath(filepath) // <9>
.filename("test.pdf") // <10>
.mimeType("application/pdf") // <11>
.description("An example pdf") // <12>
)
);
// end::builder[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import spock.lang.Subject
/**
* Tests for simple email service.
*/
@SuppressWarnings(['AbcMetric', 'JavaIoPackageAccess'])
@SuppressWarnings(['AbcMetric', 'JavaIoPackageAccess', 'UnnecessaryObjectReferences'])
class SimpleEmailServiceSpec extends Specification {

AmazonSimpleEmailService simpleEmailService = Mock(AmazonSimpleEmailService)
Expand All @@ -49,6 +49,7 @@ class SimpleEmailServiceSpec extends Specification {
from '[email protected]'
to '[email protected]'
htmlBody '<p>This is an example body</p>'
configurationSetName 'configuration-set'
tags customTags
attachment {
filename 'test.pdf'
Expand All @@ -64,6 +65,7 @@ class SimpleEmailServiceSpec extends Specification {
transactionalEmail.htmlBody == '<p>This is an example body</p>'
transactionalEmail.from == '[email protected]'
transactionalEmail.recipients == ['[email protected]']
transactionalEmail.configurationSetName == 'configuration-set'
transactionalEmail.tags == [key1: 'value1', key2: 'value2']
transactionalEmail.attachments.size() == 1
transactionalEmail.attachments.first().filename == 'test.pdf'
Expand All @@ -83,6 +85,7 @@ class SimpleEmailServiceSpec extends Specification {
htmlBody '<p>This is an example body</p>'
to '[email protected]'
from '[email protected]'
configurationSetName 'configuration-set'
tags customTags
attachment {
filepath f.absolutePath
Expand All @@ -95,6 +98,7 @@ class SimpleEmailServiceSpec extends Specification {
transactionalEmail.htmlBody == '<p>This is an example body</p>'
transactionalEmail.from == '[email protected]'
transactionalEmail.recipients == ['[email protected]']
transactionalEmail.configurationSetName == 'configuration-set'
transactionalEmail.tags == [key1: 'value1', key2: 'value2']
transactionalEmail.attachments.size() == 1
transactionalEmail.attachments.first().filename == 'groovylogo.png'
Expand Down

0 comments on commit 569a951

Please sign in to comment.