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

3

我正在尝试从我的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控制台中,发件人和收件人邮箱地址均显示为“已验证”状态,并且我已将以下“身份策略”附加到“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文档:http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SES.html

(说明:此为原文,无需翻译)
1个回答

5

AWS空间中的ARN代表整个资源名称。这包括以下有效格式:

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',

将会是:

FromArn: 'arn:aws:ses:us-west-2:xxxxxxxxxxxxxxx:identity/alex.divito@mountainviewwebtech.ca',

谢谢。这绝对解决了我遇到的错误。之后,没有出现任何错误,但我仍然没有收到任何电子邮件。我发现我必须将“身份策略”添加到两个电子邮件地址(发送者和接收者)。看起来,亚马逊最初将您的AWS帐户置于“沙箱”模式中,这会禁止向未经验证的电子邮件发送电子邮件。在“沙箱”模式被取消之前,您只能在已验证的电子邮件之间发送电子邮件,这些电子邮件都附有“身份策略”,以允许它们使用SES。 - SuperVeetz

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接