我已经在SES控制台中配置了电子邮件ID和域,并验证了它们中的每一个。我选择的区域是欧盟爱尔兰。
使用SES控制台,我可以将测试邮件发送到已验证的ID。
但是我在使用lambda代码发送邮件时遇到问题。
这是使我发疯的一段代码:
var aws = require("aws-sdk");
var nodemailer = require("nodemailer");
aws.config.update({
accessKeyId: "myaccesskey",
secretAccessKey: "mysecretkey",
region: "us-west-2"
});
var ses = new aws.SES();
exports.handler = function (event, context, callback) {
var mailOptions = {
from: "myverifiedemailaddess@domain.com",
subject: "This is an email sent from a Lambda function!",
html: `<p>You got a contact message from: </b></p>`,
to: "myverifiedemailaddess@domain.com",
// bcc: Any BCC address you want here in an array,
};
// create Nodemailer SES transporter
var transporter = nodemailer.createTransport({
SES: ses
});
// send email
transporter.sendMail(mailOptions, function (err, info) {
if (err) {
console.log("Error sending email");
callback(err);
} else {
console.log("Email sent successfully");
callback();
}
});
};
每次我使用代码发送和发送电子邮件时,都会出现以下错误:
{
"errorMessage": "Email address is not verified. The following identities failed the check in region US-WEST-2: myverifiedemailaddess@domain.com",
"errorType": "MessageRejected",
"stackTrace": [
"Request.extractError (/var/task/node_modules/aws-sdk/lib/protocol/query.js:50:29)",
"Request.callListeners (/var/task/node_modules/aws-sdk/lib/sequential_executor.js:106:20)",
"Request.emit (/var/task/node_modules/aws-sdk/lib/sequential_executor.js:78:10)",
"Request.emit (/var/task/node_modules/aws-sdk/lib/request.js:683:14)",
"Request.transition (/var/task/node_modules/aws-sdk/lib/request.js:22:10)",
"AcceptorStateMachine.runTo (/var/task/node_modules/aws-sdk/lib/state_machine.js:14:12)",
"/var/task/node_modules/aws-sdk/lib/state_machine.js:26:10",
"Request.<anonymous> (/var/task/node_modules/aws-sdk/lib/request.js:38:9)",
"Request.<anonymous> (/var/task/node_modules/aws-sdk/lib/request.js:685:12)",
"Request.callListeners (/var/task/node_modules/aws-sdk/lib/sequential_executor.js:116:18)"
]
}
答案 0 :(得分:0)
您需要在同一地区拥有SES
和Lambda
才能工作,
请仔细阅读
https://docs.aws.amazon.com/ses/latest/DeveloperGuide/regions.html#region-receive-email