我正在尝试通过适用于 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();
}
您正在尝试设置 SNS 终端节点(简单通知服务(以使用 SES(简单电子邮件服务(。请改用正确的终结点。
sesClient.setEndpoint("email.us-west-2.amazonaws.com");
但是,建议使用setRegion
方法而不是setEndpoint
。
sesClient.setRegion(Region.getRegion(Regions.US_WEST_2));