尝试使用spring cloud aws(SES)发送电子邮件时出错

时间:2017-02-01 11:59:25

标签: spring-boot spring-cloud spring-cloud-aws

我正在尝试使用spring-cloud-aws发送电子邮件。发布相关片段:

application.properties:

cloud.aws.credentials.accessKey=XXXXXXXXXXXXXXXXXXXX
cloud.aws.credentials.secretKey=YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY
cloud.aws.region.static=us-east-1

MailSendingService:

@Service
public class MailSendingService {

    @Autowired
    private MailSender mailSender;

    public void sendMailMessage() {
        SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
        simpleMailMessage.setFrom("noreply@xxx.com");
        simpleMailMessage.setTo("johndoe@gmail.com");
        simpleMailMessage.setSubject("test subject");
        simpleMailMessage.setText("test content");
        this.mailSender.send(simpleMailMessage);
    }
}

应用:

@SpringBootApplication
public class Application {

    @Autowired
    MailSendingService mailService;

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

    @Bean
    CommandLineRunner init() {
        return (evt) -> {
            mailService.sendMailMessage();
        };
    }
}

在我的POM中我正在使用:

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-aws</artifactId>
    <version>1.2.0.BUILD-SNAPSHOT</version>
</dependency>

当我运行此代码时,我收到以下错误:

  

引起:org.springframework.mail.MailSendException:失败   消息:com.amazonaws.AmazonServiceException:请求签名   我们计算的与您提供的签名不符。检查你的   AWS秘密访问密钥和签名方法。咨询服务   有关详细信息的文档。

     

此请求的规范字符串应该是'POST /

     

AMZ-SDK-调用-ID:3a35628a-ca4d-5d3f-666A-1bd596b25a0   amz-sdk-retry:3/230/485主持人:email.us-east-1.amazonaws.com   user-agent:aws-sdk-java / 1.11.18 Windows_10 / 10.0   Java_HotSpot(TM)_64-Bit_Server_VM / 25.92-B14 / 1.8.0_92   的x AMZ-日期:20170201T113844Z

     

AMZ-SDK-调用-ID; AMZ-SDK重试;主机;用户代理; X-AMZ-日期   c87e0a9aed59cebfbf123b9a248c1bece98e17c59ab38486fef0220d1f86da'

     

String-to-Sign应该是'AWS4-HMAC-SHA256 20170201T113844Z   20170201 /美东-1 / SES / aws4_request   daa69ea00e5c19ce5123fdbfe0c335d2678516925dc2042f7627d9660520ef”   (服务:AmazonSimpleEmailService;状态代码:403;错误代码:   SignatureDoesNotMatch;请求ID:   fd73a86-e872-11e6-a68d-7b50079b6d0)

我已经三次检查了钥匙。有什么想法吗?

0 个答案:

没有答案