【问题标题】:NodeMailer Gmail API in AWS Lambda not workingAWS Lambda 中的 NodeMailer Gmail API 不起作用
【发布时间】:2023-04-03 07:15:02
【问题描述】:

我正在使用带有 gmail API 的 nodemailer 来发送邮件。

以下代码:-

var nodemailer = require('nodemailer');
var transporter = await nodemailer.createTransport({
    service: 'Gmail',
    auth: {
        user: 'xx@usr.com',
        pass: 'xxx'
    }
});
console.log("Starting");
await transporter.sendMail({
    from: 'xx@google.com',
    to: 'xx@google.com',
    subject: 'Hello !',
    text: "Hello"
}, function(data, info){

});

代码在本地和发送邮件上运行良好。

但是,当在 lambda 中使用时,什么都没有发生。函数执行成功。

【问题讨论】:

    标签: amazon-web-services aws-lambda nodemailer


    【解决方案1】:

    错误可能出现在 (1) 代码、(2) IAM 权限中(对于 SES,请参阅 Nodemailer SES docConnecting to the Amazon SES SMTP EndpointSES FAQ ) 或者 (3) 网络(如果 lambda 从私有 VPC 运行且网络未完全配置)。

    或者它的工作正常(参见@TheProgrammer 在this question 中的评论)

    要查看和理解错误,请尝试以下操作:

    1. 将日志记录添加到 sendMail 方法的错误回调 (see this):

      transporter.sendMail({
          from: 'sender@example.com',
          to: 'recipient@example.com',
          subject: 'Message',
          text: 'I hope this message gets delivered!'
      }, (err, info) => {
          console.log(info.envelope);
          console.log(info.messageId);
          console.log(err);
      });
      
    2. 在 CloudWatch 日志中查看错误(直接从 在 CloudWatch 中查看日志访问,docs

    【讨论】:

      猜你喜欢
      • 2021-11-28
      • 2018-01-06
      • 1970-01-01
      • 2016-11-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-11
      • 1970-01-01
      • 2014-12-01
      相关资源
      最近更新 更多