【问题标题】:nodemailer -issue with connectionnodemailer - 连接问题
【发布时间】:2018-08-27 05:45:40
【问题描述】:

{ 错误:连接 ECONNREFUSED 127.0.0.1:587 在 Object._errnoException (util.js:1022:11) 在 _exceptionWithHostPort (util.js:1044:20) 在 TCPConnectWrap.afterConnect [as oncomplete] (net.js:1182:14) 代码:'ECONNECTION',errno:'ECONNREFUSED',系统调用:'connect',
地址:'127.0.0.1',端口:587,命令:'CONN' }

  const transporter = nodemailer.createTransport({
        service: 'smtp.gmail.com',
        auth: {
            user: 'email',
            pass: 'password '
        }
    });

我已打开 https://myaccount.google.com/lesssecureapps 。会是什么?我已经尝试过端口 - 465,25,463 ...它也无法正常工作。我该怎么办?

【问题讨论】:

  • 你用的是什么云?
  • 你是什么意思(云)?

标签: nodemailer


【解决方案1】:

你可以试试这个运输工具。 请务必使用 npm install oauth2 安装 Oauth2,然后使用 const Oauth2 = require('oauth2'); 在文件中要求它

您可以在https://console.developers.google.com/https://developers.google.com/oauthplayground/ 获取 clientid、clientsecret、refreshtoken(一定要设置 autorefresh)和 accestoken,这是为 gmail api 准备的。

  const transporter = nodemailer.createTransport({
  service: 'Gmail',
  auth: {
  type: 'OAuth2',
  user: 'yourmail',
  clientId: 'yourclientid',
  clientSecret: 'yourclientsecret',
  refreshToken: 'yourrefreshtoken',
  accessToken: 'youraccestoken',
  },
  });

希望对你有帮助!

【讨论】:

  • 您好,您如何在开发者控制台获取:clientid、clientsecret、refreshtoken(一定要设置 autorefresh)和 accestoken?用于登录 gmail 服务的帐户应该与用户相同(“yourclientid”)?还有关于令牌,应该是 oauth2 令牌,还是 gmail api 令牌?
  • 您在developers.google.com/oauthplayground 处获得clientid、clientsecret、refreshtoken 和acces 令牌,然后单击齿轮,检查使用您自己的OAuth 凭据,将您的ID 和SECRET 粘贴到此处。然后你输入 gmail api 作为范围(我忘记了我用于此的链接,但如果链接以“/”结尾,它可能会给你一个错误,所以一定要删除最后的“/”。当你有完成此操作后,单击“交换令牌的授权代码”,一旦您完成此操作,您将获得两个令牌,单击自动刷新,这样您就无需手动执行此操作并复制粘贴代码。
  • 我有一段时间没有这样做了,自从我上次配置我的项目以来,console.developers.google.com 发生了一些变化。但我想我仍然可以弄清楚,如果你愿意,我会向你发送一份更详细的获取密钥和令牌的指南。
  • 我也遇到了这个问题,添加 oauth2 包似乎没有帮助
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-02-22
  • 2017-07-12
  • 1970-01-01
  • 2019-12-24
  • 2019-06-26
相关资源
最近更新 更多