gpt4 book ai didi

java - 发送电子邮件时如何向 Amazon SES 服务提供 AWS key ?

转载 作者:行者123 更新时间:2023-11-29 04:19:02 27 4
gpt4 key购买 nike

文档说您的主目录中需要一个“共享凭证文件”,但这不适用于生产环境!那么在发送电子邮件时如何指定 AWS key 呢?它没有给出任何示例!

https://docs.aws.amazon.com/ses/latest/DeveloperGuide/examples-send-using-sdk.html

This code example assumes that you have installed the AWS SDK for Java, and that you have created a shared credentials file.

  AmazonSimpleEmailService client = 
AmazonSimpleEmailServiceClientBuilder.standard()
...
client.sendEmail(request);

他们的引用文档甚至不包含 AmazonSimpleEmailServiceClientBuilder!

https://docs.aws.amazon.com/search/doc-search.html?searchPath=documentation-guide&searchQuery=AmazonSimpleEmailServiceClientBuilder&x=3&y=8&this_doc_product=Amazon+Simple+Email+Service&this_doc_guide=API+Reference&doc_locale=en_us#facet_doc_product=Amazon%20Simple%20Email%20Service&facet_doc_guide=API%20Reference

最佳答案

如果您使用的是 EC2 或 Lambda 或任何 AWS IAM role受支持的服务,安全的方法是创建一个可以访问 SES 并将其附加到资源的角色。您将不需要维护任何凭据。 https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html#create-iam-role

以下链接提供了向您的 Java 程序提供凭据的不同方法 https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/credentials.html

如果你想在你的项目中给予

AWSCredentialsProvider credentialsProvider = new AWSCredentialsProvider() {
@Override
public void refresh() {}
@Override
public AWSCredentials getCredentials() {
return new AWSCredentials() {
@Override
public String getAWSSecretKey() {
return "YOUR_SECRET_KEY";
}
@Override
public String getAWSAccessKeyId() {
return "YOUR_ACCESS_KEY";
}
};
}
};

AmazonSimpleEmailService client = AmazonSimpleEmailServiceClientBuilder.standard()
.withCredentials(credentialsProvider).build();

关于java - 发送电子邮件时如何向 Amazon SES 服务提供 AWS key ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50401884/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com