SuperVeetz
SuperVeetz

Reputation: 2176

JavaScript - Send email using AWS SES

I'm trying to send an email from my [email protected] email address, but I am receiving the following error:

{
  "error": {
  "statusCode": 400,
  "name": "InvalidParameterValue",
  "message": "The From ARN <[email protected]> is not a valid SES identity.",
  "code": "InvalidParameterValue"
  }
}

Both the from, and to email address show a verified status in the SES console and I have attached the following Identity Policy to the [email protected] email address:

{
  "Version": "2008-10-17",
  "Statement": [
    {
        "Sid": "stmt1496992141256",
        "Effect": "Allow",
        "Principal": {
            "AWS": "arn:aws:iam::xxxxxxxxxxxxxxx:root"
        },
        "Action": [
            "ses:SendEmail",
            "ses:SendRawEmail"
        ],
        "Resource": "arn:aws:ses:us-west-2:xxxxxxxxxxxxxxx:identity/[email protected]"
    }
  ]
}

Yet when I run the following NodeJS code, I receive the above error:

Mail.send = function(email, cb) {
    var ses_mail = "From: 'AWS Tutorial Series' <" + email + ">\n";
    ses_mail = ses_mail + "To: " + "[email protected]" + "\n";
    ses_mail = ses_mail + "Subject: AWS SES Attachment Example\n";
    ses_mail = ses_mail + "MIME-Version: 1.0\n";
    ses_mail = ses_mail + "Content-Type: multipart/mixed; boundary=\"NextPart\"\n\n";
    ses_mail = ses_mail + "--NextPart\n";
    ses_mail = ses_mail + "Content-Type: text/html; charset=us-ascii\n\n";
    ses_mail = ses_mail + "This is the body of the email.\n\n";
    ses_mail = ses_mail + "--NextPart\n";
    ses_mail = ses_mail + "Content-Type: text/plain;\n";
    ses_mail = ses_mail + "Content-Disposition: attachment; filename=\"attachment.txt\"\n\n";
    ses_mail = ses_mail + "AWS Tutorial Series - Really cool file attachment!" + "\n\n";
    ses_mail = ses_mail + "--NextPart--";

    var params = {
        RawMessage: { /* required */
           Data: new Buffer(ses_mail) /* required */
        },
        Destinations: [
            email
        ],
        FromArn: '[email protected]',
        ReturnPathArn: '[email protected]',
        Source: '[email protected]',
        SourceArn: '[email protected]'
    };

    ses.sendRawEmail(params, function(err, data) {
        if (err) return cb(err);
        else return cb(null, data);
    });
};

Aws docs: http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SES.html

Upvotes: 4

Views: 2406

Answers (1)

hjpotter92
hjpotter92

Reputation: 80639

An ARN in AWS space means the whole resource name. This includes the following valid formats:

arn:partition:service:region:account-id:resource
arn:partition:service:region:account-id:resourcetype/resource
arn:partition:service:region:account-id:resourcetype:resource

and anything else is invalid. Therefore, your

FromArn: '[email protected]',

would be:

FromArn: 'arn:aws:ses:us-west-2:xxxxxxxxxxxxxxx:identity/[email protected]',

Upvotes: 5

Related Questions