为什么我不能通过 Node 上的 Amazon ses 发送电子邮件?



我正在使用" aws-sdk":"^2.117.0",我的代码看起来像这样:

var AWS = require('aws-sdk');
exports.sendAWSMail = function(message, destination){
  const ses = new AWS.SES();
  // http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SES.html#sendEmail-property
  const sendEmail = ses.sendEmail;
  var data = {
    Destination: {
     ToAddresses: [
        "blahblah@gmail.com"
     ]
    },
    Message: {
     Body: {
      Html: {
       Charset: "UTF-8",
       Data: "This message body contains HTML formatting. It can, for example, contain links like this one: <a class="ulink" href="http://docs.aws.amazon.com/ses/latest/DeveloperGuide" target="_blank">Amazon SES Developer Guide</a>."
      },
      Text: {
       Charset: "UTF-8",
       Data: "This is the message body in text format."
      }
     },
     Subject: {
      Charset: "UTF-8",
      Data: "Test email"
     }
    },
    Source: "no-reply@frutacor.com.br",
   }
  sendEmail(data)
}

但是我得到了这个错误:

typeerror:this.makerequest不是函数 在svc。(匿名函数)(/users/iagowp/desktop/trampos/frutacor/node_modules/aws-sdk/lib/service.js:499:23)

我没有在他们的网站上找到任何节点示例,但是从我在其他地方看到的内容(如这里),它看起来正确。我在做什么错?

主要问题是在第5行中,添加回调函数以记录错误和成功请求总是一个好主意。

var AWS = require('aws-sdk');
exports.sendAWSMail = function(message, destination){
  const ses = new AWS.SES();
  var data = {
    Destination: {
     ToAddresses: [
        "blahblah@gmail.com"
     ]
    },
    Message: {
     Body: {
      Html: {
       Charset: "UTF-8",
       Data: "This message body contains HTML formatting. It can, for example, contain links like this one: <a class="ulink" href="http://docs.aws.amazon.com/ses/latest/DeveloperGuide" target="_blank">Amazon SES Developer Guide</a>."
      },
      Text: {
       Charset: "UTF-8",
       Data: "This is the message body in text format."
      }
     },
     Subject: {
      Charset: "UTF-8",
      Data: "Test email"
     }
    },
    Source: "no-reply@frutacor.com.br",
   }
   ses.sendEmail(data, function(err, data) {
     if (err) console.log(err, err.stack); // an error occurred
     else     console.log(data);           // successful response
   });
}

相关内容

  • 没有找到相关文章

最新更新