JavaScript - 使用 AWS SES 发送电子邮件
Posted
技术标签:
【中文标题】JavaScript - 使用 AWS SES 发送电子邮件【英文标题】:JavaScript - Send email using AWS SES 【发布时间】:2017-11-11 03:02:43 【问题描述】:我正在尝试从我的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 文档:http://docs.aws.amazon.com/AWSjavascriptSDK/latest/AWS/SES.html
【问题讨论】:
【参考方案1】: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',
【讨论】:
谢谢。这绝对解决了我遇到的错误。之后,没有错误,但我仍然没有收到任何电子邮件。我发现我必须将Identity Policy
添加到两个电子邮件地址(发件人和收件人)。亚马逊最初似乎将您的账户 AWS 账户置于sandbox
模式,这不允许向未经验证的电子邮件发送电子邮件。在取消sandbox
模式之前,您只能在都已附加Identity Policy
以允许他们使用SES 的经过验证的电子邮件之间发送电子邮件。以上是关于JavaScript - 使用 AWS SES 发送电子邮件的主要内容,如果未能解决你的问题,请参考以下文章