Skip to content

awspring#595 Add module for aws ses API v2 #1356

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
2 changes: 2 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
- any-glob-to-any-file:
- spring-cloud-aws-autoconfigure/src/*/java/io/awspring/cloud/autoconfigure/ses/*
- spring-cloud-aws-ses/**/*
- spring-cloud-aws-autoconfigure/src/*/java/io/awspring/cloud/autoconfigure/sesv2/*
- spring-cloud-aws-sesv2/**/*
"component: sns":
- changed-files:
- any-glob-to-any-file:
Expand Down
8 changes: 7 additions & 1 deletion docs/src/main/asciidoc/_configprops.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@
|spring.cloud.aws.ses.from-arn | | Configures from ARN. Only applies to SendRawEmail operation.
|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.sesv2.configuration-set-name | | Configures configuration set name.
|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>
|spring.cloud.aws.sesv2.enabled | `+++true+++` | Enables Simple Email Service V2 integration.
|spring.cloud.aws.sesv2.endpoint | | Overrides the default endpoint.
|spring.cloud.aws.sesv2.region | | Overrides the default region.
|spring.cloud.aws.sesv2.identity-arn | | Configures identity ARN. Used only for sending authorization.
|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>
|spring.cloud.aws.sns.enabled | `+++true+++` | Enables SNS integration.
|spring.cloud.aws.sns.endpoint | | Overrides the default endpoint.
Expand All @@ -98,4 +104,4 @@
|spring.cloud.aws.sqs.queue-not-found-strategy | |
|spring.cloud.aws.sqs.region | | Overrides the default region.

|===
|===
29 changes: 29 additions & 0 deletions docs/src/main/asciidoc/ses.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -221,3 +221,32 @@ Sample IAM policy granting access to SES:
]
}
----

=== AWS SES API v2

To use AWS SES API v2 instead of v1, use the following dependency instead:

[source,xml]
----
<dependency>
<groupId>io.awspring.cloud</groupId>
<artifactId>spring-cloud-aws-starter-sesv2</artifactId>
</dependency>
----

The associated configuration options are:

[cols="3,3,1,1"]
|===
| Name | Description | Required | Default value
| `spring.cloud.aws.ses2.enabled` | Enables the SES integration. | No | `true`
| `spring.cloud.aws.ses2.endpoint` | Configures endpoint used by `SesClient`. | No |
| `spring.cloud.aws.ses2.region` | Configures region used by `SesClient`. | No |
| `spring.cloud.aws.ses2.identity-arn` | Configures identity ARN, used only for sending authorization. | No |
| `spring.cloud.aws.ses2.configuration-set-name` | The configuration set name used for every message | No |
|===

`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.
For more information about sending authorization, see the https://docs.aws.amazon.com/ses/latest/dg/sending-authorization.html[Amazon SES Developer Guide].

The `SesV2ClientCustomizer` can be used instead of the `SesClientCustomizer`.
4 changes: 3 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
<module>spring-cloud-aws-parameter-store</module>
<module>spring-cloud-aws-secrets-manager</module>
<module>spring-cloud-aws-ses</module>
<module>spring-cloud-aws-sesv2</module>
<module>spring-cloud-aws-sns</module>
<module>spring-cloud-aws-sqs</module>
<module>spring-cloud-aws-dynamodb</module>
Expand All @@ -52,13 +53,14 @@
<module>spring-cloud-aws-starters/spring-cloud-aws-starter-s3</module>
<module>spring-cloud-aws-starters/spring-cloud-aws-starter-secrets-manager</module>
<module>spring-cloud-aws-starters/spring-cloud-aws-starter-ses</module>
<module>spring-cloud-aws-starters/spring-cloud-aws-starter-sesv2</module>
<module>spring-cloud-aws-starters/spring-cloud-aws-starter-sns</module>
<module>spring-cloud-aws-starters/spring-cloud-aws-starter-sqs</module>
<module>spring-cloud-aws-samples</module>
<module>spring-cloud-aws-test</module>
<module>spring-cloud-aws-modulith</module>
<module>docs</module>
</modules>
</modules>

<dependencyManagement>
<dependencies>
Expand Down
5 changes: 5 additions & 0 deletions spring-cloud-aws-autoconfigure/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@
<artifactId>spring-cloud-aws-ses</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>io.awspring.cloud</groupId>
<artifactId>spring-cloud-aws-sesv2</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>io.awspring.cloud</groupId>
<artifactId>spring-cloud-aws-sns</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Copyright 2013-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.awspring.cloud.autoconfigure.sesv2;

import io.awspring.cloud.autoconfigure.AwsSyncClientCustomizer;
import io.awspring.cloud.autoconfigure.core.*;
import io.awspring.cloud.sesv2.SimpleEmailServiceJavaMailSender;
import io.awspring.cloud.sesv2.SimpleEmailServiceMailSender;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.*;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.mail.MailSender;
import org.springframework.mail.javamail.JavaMailSender;
import software.amazon.awssdk.services.sesv2.SesV2Client;
import software.amazon.awssdk.services.sesv2.SesV2ClientBuilder;

/**
* {@link EnableAutoConfiguration} for {@link SimpleEmailServiceMailSender} and
* {@link SimpleEmailServiceJavaMailSender}.
*
* @author Agim Emruli
* @author Eddú Meléndez
* @author Arun Patra
*/
@AutoConfiguration
@EnableConfigurationProperties(SesProperties.class)
@ConditionalOnClass({ SesV2Client.class, MailSender.class, SimpleEmailServiceJavaMailSender.class })
@AutoConfigureAfter({ CredentialsProviderAutoConfiguration.class, RegionProviderAutoConfiguration.class })
@ConditionalOnProperty(name = "spring.cloud.aws.sesv2.enabled", havingValue = "true", matchIfMissing = true)
public class SesAutoConfiguration {

@Bean
@ConditionalOnMissingBean
public SesV2Client sesV2Client(SesProperties properties, AwsClientBuilderConfigurer awsClientBuilderConfigurer,
ObjectProvider<AwsClientCustomizer<SesV2ClientBuilder>> configurer,
ObjectProvider<AwsConnectionDetails> connectionDetails,
ObjectProvider<SesV2ClientCustomizer> sesClientCustomizers,
ObjectProvider<AwsSyncClientCustomizer> awsSyncClientCustomizers) {
return awsClientBuilderConfigurer.configureSyncClient(SesV2Client.builder(), properties,
connectionDetails.getIfAvailable(), configurer.getIfAvailable(), sesClientCustomizers.orderedStream(),
awsSyncClientCustomizers.orderedStream()).build();
}

@Bean
@ConditionalOnMissingClass("jakarta.mail.Session")
@ConditionalOnMissingBean
public MailSender simpleMailSender(SesV2Client sesClient, SesProperties properties) {
return new SimpleEmailServiceMailSender(sesClient, properties.getIdentityArn(),
properties.getConfigurationSetName());
}

@Bean
@ConditionalOnClass(name = "jakarta.mail.Session")
@ConditionalOnMissingBean
public JavaMailSender javaMailSender(SesV2Client sesClient, SesProperties properties) {
return new SimpleEmailServiceJavaMailSender(sesClient, properties.getIdentityArn(),
properties.getConfigurationSetName());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright 2013-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.awspring.cloud.autoconfigure.sesv2;

import io.awspring.cloud.autoconfigure.AwsClientProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.lang.Nullable;

/**
* Properties related to AWS Simple Email Service.
*
* @author Eddú Meléndez
* @author Arun Patra
*/
@ConfigurationProperties(prefix = SesProperties.PREFIX)
public class SesProperties extends AwsClientProperties {

/**
* The prefix used for AWS credentials related properties.
*/
public static final String PREFIX = "spring.cloud.aws.sesv2";

/**
* Configures identity ARN. Used only for sending authorization.
*/
@Nullable
private String identityArn;

/**
* Configures configuration set name.
*/
@Nullable
private String configurationSetName;

@Nullable
public String getIdentityArn() {
return identityArn;
}

@Nullable
public String getConfigurationSetName() {
return configurationSetName;
}

public void setIdentityArn(@Nullable String identityArn) {
this.identityArn = identityArn;
}

public void setConfigurationSetName(@Nullable String configurationSetName) {
this.configurationSetName = configurationSetName;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright 2013-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.awspring.cloud.autoconfigure.sesv2;

import io.awspring.cloud.autoconfigure.AwsClientCustomizer;
import software.amazon.awssdk.services.sesv2.SesV2ClientBuilder;

/**
* Callback interface that can be used to customize a {@link SesV2ClientBuilder}.
*
* @author Maciej Walkowiak
* @since 3.3.0
*/
@FunctionalInterface
public interface SesV2ClientCustomizer extends AwsClientCustomizer<SesV2ClientBuilder> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright 2013-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* Auto-configuration for Amazon SES (Simple Email Service) integrations.
*/
@org.springframework.lang.NonNullApi
@org.springframework.lang.NonNullFields
package io.awspring.cloud.autoconfigure.sesv2;
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
"description": "Enables Simple Email Service integration.",
"type": "java.lang.Boolean"
},
{
"defaultValue": true,
"name": "spring.cloud.aws.sesv2.enabled",
"description": "Enables Simple Email Service integration.",
"type": "java.lang.Boolean"
},
{
"defaultValue": true,
"name": "spring.cloud.aws.s3.enabled",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ io.awspring.cloud.autoconfigure.core.RegionProviderAutoConfiguration
io.awspring.cloud.autoconfigure.imds.ImdsAutoConfiguration
io.awspring.cloud.autoconfigure.metrics.CloudWatchExportAutoConfiguration
io.awspring.cloud.autoconfigure.ses.SesAutoConfiguration
io.awspring.cloud.autoconfigure.sesv2.SesAutoConfiguration
io.awspring.cloud.autoconfigure.s3.S3TransferManagerAutoConfiguration
io.awspring.cloud.autoconfigure.s3.S3AutoConfiguration
io.awspring.cloud.autoconfigure.s3.S3CrtAsyncClientAutoConfiguration
Expand Down
Loading
Loading