Reputation: 61
For using Amazon S3, I have added spring-cloud-aws-context
and spring-cloud-starter-aws
in my pom.xml
.
I was able to implement the push and retrieve from Amazon S3 but now when I'm trying to send an email from my application, I'm getting this error:
org.springframework.mail.MailSendException: Failed messages: com.amazonaws.AmazonServiceException: Missing required header 'From'. (Service: AmazonSimpleEmailService; Status Code: 400; Error Code: InvalidParameterValue; Request ID: 3611418a-7680-11e5-b874-71fbd9180e4c); message exceptions (1) are:
Failed message 1: com.amazonaws.AmazonServiceException: Missing required header 'From'. (Service: AmazonSimpleEmailService; Status Code: 400; Error Code: InvalidParameterValue; Request ID: 3611418a-7680-11e5-b874-71fbd9180e4c)
It seems that my JavaMailSender
implementation is now trying to use Amazon SES instead of the regular org.springframework.mail.javamail.JavaMailSenderImpl
.
I'm not able to find with properties or annotation I should use to force Spring to NOT use Amazon SES (FYI, I'm using Spring Boot)
Upvotes: 1
Views: 1395
Reputation: 121552
Actually, if we take a look to the MailSenderAutoConfiguration
source code, will see this:
@Bean
@ConditionalOnMissingClass(name = "org.springframework.cloud.aws.mail.simplemail.SimpleEmailServiceJavaMailSender")
public MailSender simpleMailSender(AmazonSimpleEmailService amazonSimpleEmailService) {
return new SimpleEmailServiceMailSender(amazonSimpleEmailService);
}
@Bean
@ConditionalOnClass(Session.class)
public JavaMailSender javaMailSender(AmazonSimpleEmailService amazonSimpleEmailService) {
return new SimpleEmailServiceJavaMailSender(amazonSimpleEmailService);
}
So, both these bean delegate to the AmazonSimpleEmailService
.
Not sure why is that the problem for you, but if you'd like do not use SES
, but just your own javaMailSender
bean, consider to exclude MailSenderAutoConfiguration
from @SpringBootApplication
Exclusion can be done using an application property so that it can be toggled based on environment:
spring.autoconfigure.exclude=org.springframework.cloud.aws.autoconfigure.mail.MailSenderAutoConfiguration
Upvotes: 2