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

标签 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 控制台中均显示已验证状态,我已将以下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 文档:http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SES.html

最佳答案

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

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

关于JavaScript - 使用 AWS SES 发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44451952/

相关文章:

javascript - AWS SDK JS S3 getObject 流元数据

java - 如何为android webview制作可重用的java函数

javascript - 当用户单击键盘上的 "Enter"时,jQuery 不会阻止表单提交

仅当不是未定义/空/空时,Javascript 才将 .join() 应用于对象集合中的项目?

javascript - javascript/node.js 中的 sleep 函数

javascript - Express Server 绕过 CORS

PHP 发送电子邮件显示正文内容而不是附件

.net - 处理收到的电子邮件

javascript - 获取 js localstorage 项目不区分大小写

javascript - 由于 'Cannot read property ' add' of undefined' 错误,函数不断崩溃