简体   繁体   中英

Email Issue in AWS SES

I have configured Email Id and Domains in SES Console and verified each of them. The region i selected is EU Ireland.

Using the SES Console i am able to send test mails to the verified ID.

I am however having issues in sending mail using lambda code.

Here is the piece of code driving me crazy:

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();
        }
    });
};

Everytime i send and email using the code i get the below error:

{
  "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)"
  ]
}

You need to have SES and Lambda in the same region in order to work,

Please read this,

https://docs.aws.amazon.com/ses/latest/DeveloperGuide/regions.html#region-receive-email

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM