1
votes

I'm trying to send emails with attachments through Amazon SES for Android. The documentation suggests that I send a Raw Email but this documenation was for the AWS SDK for Java, but it does not work with the Android AWS SDK. I get this error message when I try to send a Raw Email with the Android AWS SDK:

com.amazonaws.AmazonServiceException: Could not find operation SendRawEmail for version 2010-12-01

I made the message using MimeMessage, which is set to variable message in this code:

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();
}
1
You are trying to set the SNS endpoint (Simple Notification Service) for using SES (Simple Email Service): sesClient.setEndpoint("sns.us-west-2.amazonaws.com"); Is there a reason to do this?Karthikeyan
Good catch. That was the issue, I was supposed to be using sesClient.setEndpoint("email.us-west-2.amazonaws.com");. Thank you!Liko Salas
Great! Is it working now?Karthikeyan
@Karthikeyan Yes, it is :)Liko Salas

1 Answers

1
votes

You are trying to set the SNS endpoint (Simple Notification Service) for using SES (Simple Email Service). Instead use the right endpoint.

sesClient.setEndpoint("email.us-west-2.amazonaws.com");

However it is recommended to use the setRegion method instead of setEndpoint.

sesClient.setRegion(Region.getRegion(Regions.US_WEST_2));