Skip to content

Commit a05901c

Browse files
committed
awspring#595 add module for aws ses V2
1 parent 2439fe9 commit a05901c

File tree

28 files changed

+1972
-2
lines changed

28 files changed

+1972
-2
lines changed

.github/labeler.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
- any-glob-to-any-file:
3333
- spring-cloud-aws-autoconfigure/src/*/java/io/awspring/cloud/autoconfigure/ses/*
3434
- spring-cloud-aws-ses/**/*
35+
- spring-cloud-aws-autoconfigure/src/*/java/io/awspring/cloud/autoconfigure/sesv2/*
36+
- spring-cloud-aws-sesv2/**/*
3537
"component: sns":
3638
- changed-files:
3739
- any-glob-to-any-file:

docs/src/main/asciidoc/_configprops.adoc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@
8585
|spring.cloud.aws.ses.from-arn | | Configures from ARN. Only applies to SendRawEmail operation.
8686
|spring.cloud.aws.ses.region | | Overrides the default region.
8787
|spring.cloud.aws.ses.source-arn | | Configures source ARN. Used only for sending authorization.
88+
|spring.cloud.aws.sesv2.configuration-set-name | | Configures configuration set name.
89+
|spring.cloud.aws.sesv2.dualstack-enabled | | Configure whether the AWS client should use the AWS dualstack endpoint. Note that not each AWS service supports dual-stack. For complete list check <a href="https://docs.aws.amazon.com/vpc/latest/userguide/aws-ipv6-support.html">AWS services that support IPv6</a>
90+
|spring.cloud.aws.sesv2.enabled | `+++true+++` | Enables Simple Email Service V2 integration.
91+
|spring.cloud.aws.sesv2.endpoint | | Overrides the default endpoint.
92+
|spring.cloud.aws.sesv2.region | | Overrides the default region.
93+
|spring.cloud.aws.sesv2.identity-arn | | Configures identity ARN. Used only for sending authorization.
8894
|spring.cloud.aws.sns.dualstack-enabled | | Configure whether the AWS client should use the AWS dualstack endpoint. Note that not each AWS service supports dual-stack. For complete list check <a href="https://docs.aws.amazon.com/vpc/latest/userguide/aws-ipv6-support.html">AWS services that support IPv6</a>
8995
|spring.cloud.aws.sns.enabled | `+++true+++` | Enables SNS integration.
9096
|spring.cloud.aws.sns.endpoint | | Overrides the default endpoint.
@@ -98,4 +104,4 @@
98104
|spring.cloud.aws.sqs.queue-not-found-strategy | |
99105
|spring.cloud.aws.sqs.region | | Overrides the default region.
100106

101-
|===
107+
|===

docs/src/main/asciidoc/ses.adoc

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,3 +221,32 @@ Sample IAM policy granting access to SES:
221221
]
222222
}
223223
----
224+
225+
=== AWS SES API v2
226+
227+
To use AWS SES API v2 instead of v1, use the following dependency instead:
228+
229+
[source,xml]
230+
----
231+
<dependency>
232+
<groupId>io.awspring.cloud</groupId>
233+
<artifactId>spring-cloud-aws-starter-sesv2</artifactId>
234+
</dependency>
235+
----
236+
237+
The associated configuration options are:
238+
239+
[cols="3,3,1,1"]
240+
|===
241+
| Name | Description | Required | Default value
242+
| `spring.cloud.aws.ses2.enabled` | Enables the SES integration. | No | `true`
243+
| `spring.cloud.aws.ses2.endpoint` | Configures endpoint used by `SesClient`. | No |
244+
| `spring.cloud.aws.ses2.region` | Configures region used by `SesClient`. | No |
245+
| `spring.cloud.aws.ses2.identity-arn` | Configures identity ARN, used only for sending authorization. | No |
246+
| `spring.cloud.aws.ses2.configuration-set-name` | The configuration set name used for every message | No |
247+
|===
248+
249+
`identityArn` is the ARN of the identity that is associated with the sending authorization policy that permits you to use the email address specified as `from` when sending emails.
250+
For more information about sending authorization, see the https://docs.aws.amazon.com/ses/latest/dg/sending-authorization.html[Amazon SES Developer Guide].
251+
252+
The `SesV2ClientCustomizer` can be used instead of the `SesClientCustomizer`.

pom.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
<module>spring-cloud-aws-parameter-store</module>
4141
<module>spring-cloud-aws-secrets-manager</module>
4242
<module>spring-cloud-aws-ses</module>
43+
<module>spring-cloud-aws-sesv2</module>
4344
<module>spring-cloud-aws-sns</module>
4445
<module>spring-cloud-aws-sqs</module>
4546
<module>spring-cloud-aws-dynamodb</module>
@@ -52,13 +53,14 @@
5253
<module>spring-cloud-aws-starters/spring-cloud-aws-starter-s3</module>
5354
<module>spring-cloud-aws-starters/spring-cloud-aws-starter-secrets-manager</module>
5455
<module>spring-cloud-aws-starters/spring-cloud-aws-starter-ses</module>
56+
<module>spring-cloud-aws-starters/spring-cloud-aws-starter-sesv2</module>
5557
<module>spring-cloud-aws-starters/spring-cloud-aws-starter-sns</module>
5658
<module>spring-cloud-aws-starters/spring-cloud-aws-starter-sqs</module>
5759
<module>spring-cloud-aws-samples</module>
5860
<module>spring-cloud-aws-test</module>
5961
<module>spring-cloud-aws-modulith</module>
6062
<module>docs</module>
61-
</modules>
63+
</modules>
6264

6365
<dependencyManagement>
6466
<dependencies>

spring-cloud-aws-autoconfigure/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@
6666
<artifactId>spring-cloud-aws-ses</artifactId>
6767
<optional>true</optional>
6868
</dependency>
69+
<dependency>
70+
<groupId>io.awspring.cloud</groupId>
71+
<artifactId>spring-cloud-aws-sesv2</artifactId>
72+
<optional>true</optional>
73+
</dependency>
6974
<dependency>
7075
<groupId>io.awspring.cloud</groupId>
7176
<artifactId>spring-cloud-aws-sns</artifactId>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
* Copyright 2013-2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.awspring.cloud.autoconfigure.sesv2;
17+
18+
import io.awspring.cloud.autoconfigure.AwsSyncClientCustomizer;
19+
import io.awspring.cloud.autoconfigure.core.*;
20+
import io.awspring.cloud.sesv2.SimpleEmailServiceJavaMailSender;
21+
import io.awspring.cloud.sesv2.SimpleEmailServiceMailSender;
22+
import org.springframework.beans.factory.ObjectProvider;
23+
import org.springframework.boot.autoconfigure.AutoConfiguration;
24+
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
25+
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
26+
import org.springframework.boot.autoconfigure.condition.*;
27+
import org.springframework.boot.context.properties.EnableConfigurationProperties;
28+
import org.springframework.context.annotation.Bean;
29+
import org.springframework.mail.MailSender;
30+
import org.springframework.mail.javamail.JavaMailSender;
31+
import software.amazon.awssdk.services.sesv2.SesV2Client;
32+
import software.amazon.awssdk.services.sesv2.SesV2ClientBuilder;
33+
34+
/**
35+
* {@link EnableAutoConfiguration} for {@link SimpleEmailServiceMailSender} and
36+
* {@link SimpleEmailServiceJavaMailSender}.
37+
*
38+
* @author Agim Emruli
39+
* @author Eddú Meléndez
40+
* @author Arun Patra
41+
*/
42+
@AutoConfiguration
43+
@EnableConfigurationProperties(SesProperties.class)
44+
@ConditionalOnClass({ SesV2Client.class, MailSender.class, SimpleEmailServiceJavaMailSender.class })
45+
@AutoConfigureAfter({ CredentialsProviderAutoConfiguration.class, RegionProviderAutoConfiguration.class })
46+
@ConditionalOnProperty(name = "spring.cloud.aws.sesv2.enabled", havingValue = "true", matchIfMissing = true)
47+
public class SesAutoConfiguration {
48+
49+
@Bean
50+
@ConditionalOnMissingBean
51+
public SesV2Client sesV2Client(SesProperties properties, AwsClientBuilderConfigurer awsClientBuilderConfigurer,
52+
ObjectProvider<AwsClientCustomizer<SesV2ClientBuilder>> configurer,
53+
ObjectProvider<AwsConnectionDetails> connectionDetails,
54+
ObjectProvider<SesV2ClientCustomizer> sesClientCustomizers,
55+
ObjectProvider<AwsSyncClientCustomizer> awsSyncClientCustomizers) {
56+
return awsClientBuilderConfigurer.configureSyncClient(SesV2Client.builder(), properties,
57+
connectionDetails.getIfAvailable(), configurer.getIfAvailable(), sesClientCustomizers.orderedStream(),
58+
awsSyncClientCustomizers.orderedStream()).build();
59+
}
60+
61+
@Bean
62+
@ConditionalOnMissingClass("jakarta.mail.Session")
63+
@ConditionalOnMissingBean
64+
public MailSender simpleMailSender(SesV2Client sesClient, SesProperties properties) {
65+
return new SimpleEmailServiceMailSender(sesClient, properties.getIdentityArn(),
66+
properties.getConfigurationSetName());
67+
}
68+
69+
@Bean
70+
@ConditionalOnClass(name = "jakarta.mail.Session")
71+
@ConditionalOnMissingBean
72+
public JavaMailSender javaMailSender(SesV2Client sesClient, SesProperties properties) {
73+
return new SimpleEmailServiceJavaMailSender(sesClient, properties.getIdentityArn(),
74+
properties.getConfigurationSetName());
75+
}
76+
77+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Copyright 2013-2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.awspring.cloud.autoconfigure.sesv2;
17+
18+
import io.awspring.cloud.autoconfigure.AwsClientProperties;
19+
import org.springframework.boot.context.properties.ConfigurationProperties;
20+
import org.springframework.lang.Nullable;
21+
22+
/**
23+
* Properties related to AWS Simple Email Service.
24+
*
25+
* @author Eddú Meléndez
26+
* @author Arun Patra
27+
*/
28+
@ConfigurationProperties(prefix = SesProperties.PREFIX)
29+
public class SesProperties extends AwsClientProperties {
30+
31+
/**
32+
* The prefix used for AWS credentials related properties.
33+
*/
34+
public static final String PREFIX = "spring.cloud.aws.sesv2";
35+
36+
/**
37+
* Configures identity ARN. Used only for sending authorization.
38+
*/
39+
@Nullable
40+
private String identityArn;
41+
42+
/**
43+
* Configures configuration set name.
44+
*/
45+
@Nullable
46+
private String configurationSetName;
47+
48+
@Nullable
49+
public String getIdentityArn() {
50+
return identityArn;
51+
}
52+
53+
@Nullable
54+
public String getConfigurationSetName() {
55+
return configurationSetName;
56+
}
57+
58+
public void setIdentityArn(@Nullable String identityArn) {
59+
this.identityArn = identityArn;
60+
}
61+
62+
public void setConfigurationSetName(@Nullable String configurationSetName) {
63+
this.configurationSetName = configurationSetName;
64+
}
65+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright 2013-2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.awspring.cloud.autoconfigure.sesv2;
17+
18+
import io.awspring.cloud.autoconfigure.AwsClientCustomizer;
19+
import software.amazon.awssdk.services.sesv2.SesV2ClientBuilder;
20+
21+
/**
22+
* Callback interface that can be used to customize a {@link SesV2ClientBuilder}.
23+
*
24+
* @author Maciej Walkowiak
25+
* @since 3.3.0
26+
*/
27+
@FunctionalInterface
28+
public interface SesV2ClientCustomizer extends AwsClientCustomizer<SesV2ClientBuilder> {
29+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright 2013-2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/**
18+
* Auto-configuration for Amazon SES (Simple Email Service) integrations.
19+
*/
20+
@org.springframework.lang.NonNullApi
21+
@org.springframework.lang.NonNullFields
22+
package io.awspring.cloud.autoconfigure.sesv2;

spring-cloud-aws-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
"description": "Enables Simple Email Service integration.",
1313
"type": "java.lang.Boolean"
1414
},
15+
{
16+
"defaultValue": true,
17+
"name": "spring.cloud.aws.sesv2.enabled",
18+
"description": "Enables Simple Email Service integration.",
19+
"type": "java.lang.Boolean"
20+
},
1521
{
1622
"defaultValue": true,
1723
"name": "spring.cloud.aws.s3.enabled",

spring-cloud-aws-autoconfigure/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ io.awspring.cloud.autoconfigure.core.RegionProviderAutoConfiguration
44
io.awspring.cloud.autoconfigure.imds.ImdsAutoConfiguration
55
io.awspring.cloud.autoconfigure.metrics.CloudWatchExportAutoConfiguration
66
io.awspring.cloud.autoconfigure.ses.SesAutoConfiguration
7+
io.awspring.cloud.autoconfigure.sesv2.SesAutoConfiguration
78
io.awspring.cloud.autoconfigure.s3.S3TransferManagerAutoConfiguration
89
io.awspring.cloud.autoconfigure.s3.S3AutoConfiguration
910
io.awspring.cloud.autoconfigure.s3.S3CrtAsyncClientAutoConfiguration

0 commit comments

Comments
 (0)