What is the required configuration steps to have a Spring Boot application send simple e-mails via AWS SES?
You may try below steps to fix your issue. I tried these changes in the forked repo from you and it works for me.
- Add dependency "com.amazonaws:aws-java-sdk-ses" in
pom.xml
file. - Create an auto configuration class to configure the mail sender bean. Below is example. The
AWSCredentialsProvider
is configured and provided byspring-cloud-starter-aws
out-of-the-box.
.
@Configuration
public class SimpleMailAutoConfig {
@Bean
public AmazonSimpleEmailService amazonSimpleEmailService(AWSCredentialsProvider credentialsProvider) {
return AmazonSimpleEmailServiceClientBuilder.standard()
.withCredentials(credentialsProvider)
// Replace US_WEST_2 with the AWS Region you're using for
// Amazon SES.
.withRegion(Regions.US_WEST_2).build();
}
@Bean
public MailSender mailSender(AmazonSimpleEmailService ses) {
return new SimpleEmailServiceMailSender(ses);
}
}
3. Use spring API to send mail using the configured mail sender.
Hope it helps.
Edit:
If you need to use JavaMailSender
instead of MailSender
(for instance when you want to send attachments), simply configure SimpleEmailServiceJavaMailSender
instead of SimpleEmailServiceMailSender
.
Like this:
@Bean
public JavaMailSender mailSender(AmazonSimpleEmailService ses) {
return new SimpleEmailServiceJavaMailSender(ses);
}
I used AWS SES in a Spring Boot web project some time ago, but I haven't used Spring Cloud AWS to integrate my application with the mail service.
Instead I simply included spring-boot-starter-mail
among the project dependencies (pom.xml):
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
Then I set SMTP server parameters in my application.properties
. In my case I used these properties:
spring.mail.host=email-smtp.eu-west-1.amazonaws.com
spring.mail.port=465
spring.mail.protocol=smtps
spring.mail.smtps.auth=true
spring.mail.smtp.ssl.enable=true
spring.mail.username=<my-user>
spring.mail.password=<my-password>
Note: server host and port may vary.
Spring Boot will create a default JavaMailSender
instance, configuring it with the previos parametes. You can use this object to send emails...
Probably this in not the best approach to AWS SES integration with a Spring Boot application, but it works fine for me.