1

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

应用程序属性:

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

邮件发送服务:

@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-invocation-id:3a35628a-ca4d-5d3f-666a-1bd596b25a0 amz-sdk-retry:3/230/485 主机:email.us-east-1.amazonaws.com 用户代理: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-date:20170201T113844Z

amz-sdk-invocation-id;amz-sdk-retry;主机;用户代理;x-amz-date c87e0a9aed59cebfbf123b9a248c1bece98e17c59ab38486fef0220d1f86da'

The String-to-Sign should have been 'AWS4-HMAC-SHA256 20170201T113844Z 20170201/us-east-1/ses/aws4_request daa69ea00e5c19ce5123fdbfe0c335d2678516925dc2042f7627d9660520ef' (Service: AmazonSimpleEmailService; Status Code: 403; Error Code: SignatureDoesNotMatch; Request ID: fd73a86-e872 -11e6-a68d-7b50079b6d0)

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

4

0 回答 0