Liko Salas
Liko Salas

Reputation: 21

Sending E-mail with Attachment for Amazon AWS SES for Android?

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();
}

Upvotes: 1

Views: 1950

Answers (1)

Ruby
Ruby

Reputation: 1441

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));

Upvotes: 1

Related Questions