无法使用Java中的Amazon SES发送电子邮件
我正在使用下面提到的代码发送电子邮件。
public static void send(String email, String subject, String body) {
try {
fromEmail = "abc.@xyz.com";
Content subjectContent = new Content(subject);
Destination destination = new Destination().withToAddresses(new String[] { "cde@gmail.com" });
Content htmlContent = new Content().withData("<h1>Hello - I hope you're having a good day.</h1>");
Body msgBody = new Body().withHtml(htmlContent);
// Create a message with the specified subject and body.
Message message = new Message().withSubject(subjectContent).withBody(msgBody);
SendEmailRequest request = new SendEmailRequest()
.withSource(fromEmail)
.withDestination(destination)
.withMessage(message);
SendRawEmailRequest sendRawEmailRequest = new SendRawEmailRequest()
.withSource(fromEmail)
.withDestinations(destination.getBccAddresses())
.withRawMessage(new RawMessage());
AWSCredentials credentials = new BasicAWSCredentials(userName,password);
AmazonSimpleEmailServiceClient sesClient = new AmazonSimpleEmailServiceClient(credentials);
// ListVerifiedEmailAddressesResult verifiedEmails =
// sesClient.listVerifiedEmailAddresses();
SendRawEmailResult result = sesClient.sendRawEmail(sendRawEmailRequest);
System.out.println(result + "Email sent");
} catch (Exception e) {
logger.error("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.{}" + e.getMessage());
e.printStackTrace();
}
}
我收到下面提到的错误。
com.amazonaws.AmazonServiceException:我们计算的请求签名与您提供的签名不匹配。 检查您的AWS秘密访问密钥和签名方法。 详细信息请参阅服务文档。 该请求的规范字符串应该是'POST /
host:email.us-east-1.amazonaws.com user-agent:aws-sdk-java / 1.9.0 Linux / 3.19.0-25-generic Java_HotSpot(TM)_64-Bit_Server_VM / 25.66-b17 / 1.8.0_66 X-AMZ-日期:20160223T062544Z
host; user-agent; x-amz-date 4c1f25e3dcf887bd49756ddd01c5e923cf49f2affa73adfc7059d00140032edf'
(服务:AmazonSimpleEmailService;状态码:403;错误代码:SignatureDoesNotMatch;
您提供的凭据不正确。 你正在给IAM用户名和密码。 相反,您必须提供access_key_id
和access_key_id
。
AWSCredentials credentials = new BasicAWSCredentials(access_key_id, secret_access_key)
请参阅:在AWS SDK for Java中提供AWS Credentials
链接地址: http://www.djcxy.com/p/38995.html上一篇: Not able to send Email using Amazon SES in Java
下一篇: SignatureDoesNotMatch when attempting to list a product on Amazon API