0

我尝试使用 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();
        });
    }
4

1 回答 1

1

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

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

于 2013-11-25T00:14:22.303 回答