Skip to content

Commit

Permalink
Add fromArn is configuration property to SNS integration (awspring#…
Browse files Browse the repository at this point in the history
…1026)

Fixes awspring#1025

---------

Co-authored-by: Maciej Walkowiak <[email protected]>
  • Loading branch information
thomas-burko and maciejwalkowiak committed Mar 10, 2024
1 parent f4a2613 commit 1cde312
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 3 deletions.
Binary file added docs/src/main/.DS_Store
Binary file not shown.
5 changes: 3 additions & 2 deletions docs/src/main/asciidoc/_configprops.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
|spring.cloud.aws.credentials.instance-profile | `+++false+++` | Configures an instance profile credentials provider with no further configuration.
|spring.cloud.aws.credentials.profile | | The AWS profile.
|spring.cloud.aws.credentials.secret-key | | The secret key to be used with a static provider.
|spring.cloud.aws.credentials.sts.async-credentials-update | |
|spring.cloud.aws.credentials.sts.async-credentials-update | |
|spring.cloud.aws.credentials.sts.role-arn | | ARN of IAM role associated with STS. If not provided this will be read from {@link software.amazon.awssdk.core.SdkSystemSetting}.
|spring.cloud.aws.credentials.sts.role-session-name | | Role session name that will be used by credentials provider. By default this is read from {@link software.amazon.awssdk.core.SdkSystemSetting}.
|spring.cloud.aws.credentials.sts.web-identity-token-file | | Absolute path to the web identity token file that will be used by credentials provider. By default this will be read from {@link software.amazon.awssdk.core.SdkSystemSetting}.
Expand Down Expand Up @@ -38,7 +38,7 @@
|spring.cloud.aws.parameterstore.reload.strategy | | Reload strategy to run when properties change.
|spring.cloud.aws.region.instance-profile | `+++false+++` | Configures an instance profile region provider with no further configuration.
|spring.cloud.aws.region.profile | | The AWS profile.
|spring.cloud.aws.region.static | |
|spring.cloud.aws.region.static | |
|spring.cloud.aws.s3.accelerate-mode-enabled | | Option to enable using the accelerate endpoint when accessing S3. Accelerate endpoints allow faster transfer of objects by using Amazon CloudFront's globally distributed edge locations.
|spring.cloud.aws.s3.checksum-validation-enabled | | Option to disable doing a validation of the checksum of an object stored in S3.
|spring.cloud.aws.s3.chunked-encoding-enabled | | Option to enable using chunked encoding when signing the request payload for {@link software.amazon.awssdk.services.s3.model.PutObjectRequest} and {@link software.amazon.awssdk.services.s3.model.UploadPartRequest}.
Expand All @@ -63,6 +63,7 @@
|spring.cloud.aws.ses.endpoint | | Overrides the default endpoint.
|spring.cloud.aws.ses.region | | Overrides the default region.
|spring.cloud.aws.ses.source-arn | | Configures source ARN. Used only for sending authorization.
|spring.cloud.aws.ses.from-arn | | Configures from ARN. Used only for sending authorization in the SendRawEmail operation.
|spring.cloud.aws.ses.configuration-set-name | The configuration set name used for every message.
|spring.cloud.aws.sns.enabled | `+++true+++` | Enables SNS integration.
|spring.cloud.aws.sns.endpoint | | Overrides the default endpoint.
Expand Down
5 changes: 5 additions & 0 deletions docs/src/main/asciidoc/ses.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ The Spring Boot Starter for SES provides the following configuration options:
| `spring.cloud.aws.ses.endpoint` | Configures endpoint used by `SesClient`. | No |
| `spring.cloud.aws.ses.region` | Configures region used by `SesClient`. | No |
| `spring.cloud.aws.ses.source-arn` | Configures source ARN, used only for sending authorization. | No |
| `spring.cloud.aws.ses.from-arn` | Configures from ARN, used only for sending authorization in the SendRawEmail operation. | No |
| `spring.cloud.aws.ses.configuration-set-name` | The configuration set name used for every message | No |
|===

Expand All @@ -148,13 +149,17 @@ an SES service where the client is overridden to use a valid region (`EU-WEST-1`
`sourceArn` is the ARN of the identity that is associated with the sending authorization policy. For information about when to use this parameter, see the
description see https://docs.aws.amazon.com/ses/latest/dg/sending-authorization-delegate-sender-tasks-email.html[Amazon SES Developer Guide].

`fromArn` is the ARN of the identity that is associated with the sending authorization policy that permits you to specify a particular "From" address in the header of the raw email.
For information about when to use this parameter, see the description see https://docs.aws.amazon.com/ses/latest/dg/sending-authorization-delegate-sender-tasks-email.html[Amazon SES Developer Guide].

`configurationSetName` sets the configuration set name on mail sender level and applies to every mail. For information about when to use this parameter, see the
description https://docs.aws.amazon.com/ses/latest/dg/using-configuration-sets.html[Using configuration sets in Amazon SES].

[source,properties,indent=0]
----
spring.cloud.aws.ses.region=eu-west-1
spring.cloud.aws.ses.source-arn=arn:aws:ses:eu-west-1:123456789012:identity/example.com
spring.cloud.aws.ses.from-arn=arn:aws:ses:eu-west-1:123456789012:identity/example.com
spring.cloud.aws.ses.configuration-set-name=ConfigSet
----

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ public class SesProperties extends AwsClientProperties {
@Nullable
private String configurationSetName;

/**
* Configures from ARN. Only applies to SendRawEmail operation.
*/
@Nullable
private String fromArn;

@Nullable
public String getSourceArn() {
return sourceArn;
Expand All @@ -55,11 +61,21 @@ public String getConfigurationSetName() {
return configurationSetName;
}

@Nullable
public String getFromArn() {
return fromArn;
}

public void setSourceArn(@Nullable String sourceArn) {
this.sourceArn = sourceArn;
}

public void setConfigurationSetName(@Nullable String configurationSetName) {
this.configurationSetName = configurationSetName;
}

public void setFromArn(@Nullable String fromArn) {
this.fromArn = fromArn;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ public class SimpleEmailServiceJavaMailSender extends SimpleEmailServiceMailSend
@Nullable
private FileTypeMap defaultFileTypeMap;

@Nullable
private String fromArn;

public SimpleEmailServiceJavaMailSender(SesClient sesClient) {
this(sesClient, null);
}
Expand All @@ -87,6 +90,12 @@ public SimpleEmailServiceJavaMailSender(SesClient sesClient, @Nullable String so
super(sesClient, sourceArn, configurationSetName);
}

public SimpleEmailServiceJavaMailSender(SesClient sesClient, @Nullable String sourceArn,
@Nullable String configurationSetName, @Nullable String fromArn) {
super(sesClient, sourceArn, configurationSetName);
this.fromArn = fromArn;
}

/**
* Allow Map access to the JavaMail properties of this sender, with the option to add or override specific entries.
* <p>
Expand Down Expand Up @@ -212,7 +221,7 @@ public void send(MimeMessage... mimeMessages) throws MailException {
RawMessage rawMessage = createRawMessage(mimeMessage);

SendRawEmailResponse sendRawEmailResponse = getEmailService()
.sendRawEmail(SendRawEmailRequest.builder().sourceArn(getSourceArn())
.sendRawEmail(SendRawEmailRequest.builder().sourceArn(getSourceArn()).fromArn(this.fromArn)
.configurationSetName(getConfigurationSetName()).rawMessage(rawMessage).build());

if (LOGGER.isDebugEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,21 @@ void testSendMimeMessageWithConfigurationSetNameSet() throws MessagingException
assertThat(request.getValue().configurationSetName()).isEqualTo("Configuration Set");
}

@Test
void testSendMimeMessageWithFromArnSet() throws MessagingException {
SesClient emailService = mock(SesClient.class);
JavaMailSender mailSender = new SimpleEmailServiceJavaMailSender(emailService, null, null,
"eu-west-1:123456789012:identity/example.com");
ArgumentCaptor<SendRawEmailRequest> request = ArgumentCaptor.forClass(SendRawEmailRequest.class);
when(emailService.sendRawEmail(request.capture()))
.thenReturn(SendRawEmailResponse.builder().messageId("123").build());
MimeMessage mimeMessage = createMimeMessage();

mailSender.send(mimeMessage);

assertThat(request.getValue().fromArn()).isEqualTo("eu-west-1:123456789012:identity/example.com");
}

@Test
void testSendMultipleMimeMessages() throws Exception {
SesClient emailService = mock(SesClient.class);
Expand Down

0 comments on commit 1cde312

Please sign in to comment.