gpt4 book ai didi

amazon-web-services - SignatureDoesNotMatch,我们计算的请求签名与您提供的签名不匹配

转载 作者:行者123 更新时间:2023-12-04 15:58:14 35 4
gpt4 key购买 nike

我已经查看了关于 SO 的其他问题,所有这些问题都没有将 SES 和 Java 作为问题的一部分。

异常(exception)

Exception in thread "main" com.amazonaws.AmazonServiceException: Status Code: 403, AWS Service: AmazonSimpleEmailService, AWS Request ID: 6828fb27-8972-11e3-9700-b705133266ce, AWS Error Code: SignatureDoesNotMatch, AWS Error Message: The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details.
at com.amazonaws.http.AmazonHttpClient.handleErrorResponse(AmazonHttpClient.java:773)
at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:417)
at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:229)
at com.amazonaws.services.simpleemail.AmazonSimpleEmailServiceClient.invoke(AmazonSimpleEmailServiceClient.java:1254)
at com.amazonaws.services.simpleemail.AmazonSimpleEmailServiceClient.listVerifiedEmailAddresses(AmazonSimpleEmailServiceClient.java:296)
at com.amazonaws.services.simpleemail.AmazonSimpleEmailServiceClient.listVerifiedEmailAddresses(AmazonSimpleEmailServiceClient.java:1132)
at com.mcruiseon.server.amazonses.test.AWSJavaMailSample.verifyEmailAddress(AWSJavaMailSample.java:169)
at com.mcruiseon.server.amazonses.test.AWSJavaMailSample.main(AWSJavaMailSample.java:84)

源代码
public class AWSJavaMailSample {
private static final String TO = "personalemail@gmail.com";
private static final String FROM = "admin@myproductdomain.com";
private static final String BODY = "Hello World!";
private static final String SUBJECT = "Hello World!";

public static void main(String[] args) throws IOException {
AWSCredentials credentials = new ClasspathPropertiesFileCredentialsProvider()
.getCredentials();
AmazonSimpleEmailService ses = new AmazonSimpleEmailServiceClient(
credentials);
Region usWest2 = Region.getRegion(Regions.US_EAST_1);
ses.setRegion(usWest2);
verifyEmailAddress(ses, FROM);
// verifyEmailAddress(ses, TO);
Properties props = new Properties();
props.setProperty("mail.transport.protocol", "aws");
props.setProperty("mail.aws.user", "ses-smtp-user.some_number") ;
props.setProperty("mail.aws.password", "password_setup_for_this_user");
Session session = Session.getInstance(props);
try {
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(FROM));
msg.addRecipient(Message.RecipientType.TO, new InternetAddress(TO));
msg.setSubject(SUBJECT);
msg.setText(BODY);
msg.saveChanges();

Transport t = new AWSJavaMailTransport(session, null);
t.connect();
t.sendMessage(msg, null);

t.close();
} catch (AddressException e) {
e.printStackTrace();
System.out
.println("Caught an AddressException, which means one or more of your "
+ "addresses are improperly formatted.");
} catch (MessagingException e) {
e.printStackTrace();
System.out
.println("Caught a MessagingException, which means that there was a "
+ "problem sending your message to Amazon's E-mail Service check the "
+ "stack trace for more information.");
}
}
private static void verifyEmailAddress(AmazonSimpleEmailService ses,
String address) {
ListVerifiedEmailAddressesResult verifiedEmails = ses
.listVerifiedEmailAddresses();
if (verifiedEmails.getVerifiedEmailAddresses().contains(address))
return;

ses.verifyEmailAddress(new VerifyEmailAddressRequest()
.withEmailAddress(address));
System.out.println("Please check the email address " + address
+ " to verify it");
System.exit(0);
}
}

SES 设置
  • 将 myproductdomain.com 添加到域。
  • 将 admin@myproductdomain.com 添加到电子邮件地址。

  • AwsCredentials.properties
  • 对于 secretKey="aws 网站登录密码"
  • 对于 accesskey="https://console.aws.amazon.com/iam/home#users,安全凭证,对于 ses-smtp-user.some_number,访问 key "

  • 我正在从 eclipse 插件中尝试 SES 的“hello world”。应该开箱即用。

    最佳答案

    我相信问题在于您使用的是“ses-smtp-user.some_number”。
    您会看到,使用 SES,有两种发送电子邮件的方式。

  • 使用网络服务 (AmazonSimpleEmailServiceClient)
  • 使用 SMTP

  • 创建的用户用于 smtp,ses-smtp-user.some_number。
    您正在使用该凭据进行 Web 服务调用。

    我的建议是创建一个普通用户(不是从 SES 屏幕),并分配 SES 权限。
    请注意,新创建的凭据现在不适用于 SMTP。

    如果您想要一个同时适用于 SMTP 和 Web 服务的凭证,您可能需要阅读以下内容: http://docs.aws.amazon.com/ses/latest/DeveloperGuide/smtp-credentials.html#smtp-credentials-convert

    关于amazon-web-services - SignatureDoesNotMatch,我们计算的请求签名与您提供的签名不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21449220/

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