SignatureDoesnotMatch,我们计算的请求签名与您提供的签名不匹配



我已经看过其他问题,因此,它们都没有SES和Java作为他们问题的一部分。

异常

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设置

  1. 将myproductdomain.com添加到域中。
  2. 将admin@myproductdomain.com添加到电子邮件地址。

awscredentials.properties

  1. for SecretKey =" AWS网站登录密码"
  2. for AccessKey =" https://console.aws.amazon.com/iam/home#users,安全凭证,ses-smtp-user.some_number,access键"

我正在尝试使用Eclipse插件的SES的" Hello World"。应该在开箱即用的地方工作。

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

  • 使用Web服务(AmazonSimpleemailServiceClient)
  • 使用SMTP

创建的用户适用于SMTP,SES-SMTP-USER.SOME_NUMBER。您正在使用该凭据进行Web服务调用。

我的建议是创建普通用户(不是来自SES屏幕),并分配SES权限。请注意,新创建的凭据现在无法使用SMTP。

如果您想要与SMTP和Web服务一起使用的凭据,则可能需要阅读:http://docs.aws.amazon.com/ses/latest/developerguide/smtp-credentials.htmls.html#smtp-credentials-convert

相关内容

  • 没有找到相关文章

最新更新