【问题标题】:Nodemailer and GMail with access tokens带有访问令牌的 Nodemailer 和 GMail
【发布时间】:2013-11-24 18:40:22
【问题描述】:

我尝试使用 Nodemailer 通过我的 GMail 帐户发送电子邮件,但它不起作用,它在本地工作,但在我的远程服务器上,我收到来自 Google 的电子邮件“有人正在使用您的帐户......”

我该怎么办?

    exports.contact = function(req, res){
        var name = req.body.name;
        var from = req.body.from;
        var message = req.body.message;
        var to = '******@gmail.com';
        var transport = nodemailer.createTransport("SMTP", {
            service: 'Gmail',
            auth: {
                XOAuth2: {
                    user: "******@gmail.com",
                    clientId: "*****",
                    clientSecret: "******",
                    refreshToken: "******",
                }
            }
        });
        var options = {
            from: from,
            to: to, 
            subject: name,
            text: message
        }
        transport.sendMail(options, function(error, response) {
          if (error) {
            console.log(error);
          } else {
            console.log(response);
          }
          transport.close();
        });
    }

【问题讨论】:

标签: node.js express gmail nodemailer


【解决方案1】:

查看Unable to send email via google smtp on centos VPS的解决方案:

就我而言,我的脚本位于 VPS 上,因此我无法使用浏览器加载任何 url。我做了什么:改变了我的 gmail 密码。 Gmail > 设置 > 帐户。然后在谷歌帐户中,他们列出了被谷歌阻止的可疑登录(这些是我的脚本尝试的登录)。然后我点击选项“是的,那是我”。之后,我的脚本工作了(使用新密码)。

【讨论】:

  • 好的,但是还有其他解决方案吗,因为我们必须更改密码并解锁我们的脚本似乎很奇怪......
猜你喜欢
  • 2017-05-23
  • 2013-01-18
  • 1970-01-01
  • 2013-11-21
  • 1970-01-01
  • 2018-01-31
  • 2021-02-05
  • 2019-04-11
  • 1970-01-01
相关资源
最近更新 更多