我正在尝试通过适用于Android的Amazon SES发送带有附件的电子邮件。该文档建议我发送原始电子邮件,但此文档适用于Java的AWS开发工具包,但不适用于Android AWS开发工具包。当我尝试使用Android AWS开发工具包发送原始电子邮件时收到以下错误消息:
com.amazonaws.AmazonServiceException: Could not find operation SendRawEmail for version 2010-12-01
我使用MimeMessage发出了消息,该代码在此代码中设置为可变消息:
public void sendEmail() {
try {
AWSCredentials credentials = new BasicAWSCredentials(ACCESS_KEY, SECRET_KEY);
AmazonSimpleEmailServiceClient sesClient = new AmazonSimpleEmailServiceClient(credentials);
sesClient.setEndpoint("https://sns.us-west-2.amazonaws.com");
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
message.writeTo(outputStream);
RawMessage rawMessage =
new RawMessage(ByteBuffer.wrap(outputStream.toByteArray()));
SendRawEmailRequest rawEmailRequest =
new SendRawEmailRequest(rawMessage);
sesClient.sendRawEmail(rawEmailRequest);
System.out.println("Email sent!");
} catch (Exception ex) {
System.out.println("Email Failed");
System.err.println("Error message: " + ex.getMessage());
ex.printStackTrace();
}
答案 0 :(得分:1)
您正在尝试将SNS端点(简单通知服务)设置为使用SES(简单电子邮件服务)。而是使用正确的端点。
sesClient.setEndpoint("email.us-west-2.amazonaws.com");
但是,建议使用setRegion
方法而不是setEndpoint
。
sesClient.setRegion(Region.getRegion(Regions.US_WEST_2));