对于使用Amazon S3,我在spring-cloud-aws-context
添加了spring-cloud-starter-aws
和pom.xml
。
我能够从Amazon S3实现推送和检索,但现在当我尝试从我的应用程序发送电子邮件时,我收到此错误:
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)
我的JavaMailSender
实现似乎正在尝试使用Amazon SES而不是常规org.springframework.mail.javamail.JavaMailSenderImpl
。
我无法找到我应该使用的属性或注释来强制Spring不使用Amazon SES(仅供参考,我正在使用Spring Boot)
答案 0 :(得分:2)
实际上,如果我们查看MailSenderAutoConfiguration
源代码,会看到:
@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);
}
因此,这两个bean都委托给AmazonSimpleEmailService
。
不确定为什么这个问题适合您,但如果您不想使用SES
,而只使用自己的javaMailSender
bean,请考虑从{{1}中排除MailSenderAutoConfiguration
}}
可以使用应用程序属性进行排除,以便可以根据环境进行切换:
@SpringBootApplication