我正在尝试在我的 SpringBoot 项目中使用AWS SES Simple Email Service发送电子邮件
知道我在AWS上验证了电子邮件,并且还创建了AWS_ACCESS_KEY
和AWS_SECRET_KEY
。
这是我的代码:
public static void amazonSimpleEmailService(String to, String subject, String htmlBody, String textBody) {
AmazonSimpleEmailService client = AmazonSimpleEmailServiceClientBuilder.standard()
.withCredentials(
new AWSStaticCredentialsProvider(new BasicAWSCredentials(AWS_ACCESS_KEY, AWS_SECRET_KEY)))
.withRegion(Regions.EU_WEST_1).build();
SendEmailRequest request = new SendEmailRequest().withDestination(new Destination().withToAddresses(to))
.withMessage(new Message()
.withBody(new Body().withHtml(new Content().withCharset("UTF_8").withData(htmlBody))
.withText(new Content().withCharset("UTF-8").withData(textBody)))
.withSubject(new Content().withCharset("UTF-8").withData(subject)))
.withSource(MAIL_ADMIN);
client.sendEmail(request);
}
在 Jenkins (EC2实例)上构建代码时,会发生
Caused by: com.amazonaws.SdkClientException: Unable to load AWS credentials from any provider in the chain: [com.amazonaws.auth.EC2ContainerCredentialsProviderWrapper@55fe41ea: The requested metadata is not found at http://169.254.169.254/latest/meta-data/iam/security-credentials/, com.amazonaws.auth.profile.ProfileCredentialsProvider@2aceadd4: profile file cannot be null]
我怀疑缺少什么,但是我找不到它。