JavaScript - 使用AWS SES发送电子邮件

时间:2017-06-09 07:35:16

标签: javascript node.js email amazon-web-services amazon-ses

我正在尝试从我的alex.divito@mountainviewwebtech.ca电子邮件地址发送电子邮件,但我收到以下错误:

{
  "error": {
  "statusCode": 400,
  "name": "InvalidParameterValue",
  "message": "The From ARN <alex.divito@mountainviewwebtech.ca> is not a valid SES identity.",
  "code": "InvalidParameterValue"
  }
}

来自和发送电子邮件地址在SES控制台中显示verified状态,并且我已将以下Identity Policy附加到alex.divito@mountainviewwebtech.ca电子邮件地址:

{
  "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/alex.divito@mountainviewwebtech.ca"
    }
  ]
}

然而,当我运行以下NodeJS代码时,我收到上述错误:

Mail.send = function(email, cb) {
    var ses_mail = "From: 'AWS Tutorial Series' <" + email + ">\n";
    ses_mail = ses_mail + "To: " + "alexdiv87@hotmail.com" + "\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: 'alex.divito@mountainviewwebtech.ca',
        ReturnPathArn: 'alex.divito@mountainviewwebtech.ca',
        Source: 'alex.divito@mountainviewwebtech.ca',
        SourceArn: 'alex.divito@mountainviewwebtech.ca'
    };

    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

1 个答案:

答案 0 :(得分:3)

ARN in AWS space表示整个资源名称。这包括以下有效格式:

Red Hat Enterprise Linux Server release 5.11 (Tikanga)

其他任何内容都无效。因此,你的

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

将是:

FromArn: 'alex.divito@mountainviewwebtech.ca',
相关问题