JavaScript – 使用AWS 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文档: http : //docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SES.html

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