我正在使用nodemailer发送电子邮件,并且我还使用应用程序密码作为用户密码。但我无法弄清楚为什么会出现此错误?

问题描述 投票:0回答:1
  const transporter =  nodemailer.createTransport({
        source: 'gmail',
      auth: {
        user: process.env.EMAIL,
        pass: process.env.EMAIL_PASSWORD
      },
    });

    const mailoptions = {
      from:`Anshul kumar <${process.env.EMAIL}>`,
      to: Email,
      subject: "Reset your Password",
      text: "hi welcome",
      html: `<a href="http://localhost:5000/password/resetpassword/${newid}">click on this link to reset your password</a>`,
    };
    
    transporter.sendMail(mailoptions, (error, info) => {
      if (error) {
        console.log(error);
        res.status(500).json({ message: "can not send email", success: false });
      } else {
        res
          .status(200)
          .json({ message: "email sent successfully", success: true });
      }
    }); 

这就是错误:

错误:连接ECONNREFUSED 127.0.0.1:587 在 TCPConnectWrap.afterConnect [作为未完成] (节点:net:1494:16) { 错误号:-4078, 代码:'ESOCKET', 系统调用:'连接', 地址:'127.0.0.1', 端口:587, 命令:'CONN' }

当我使用主机作为“spmt-gmail.com”时出现此错误

Error: Invalid login: 535-5.7.8 Username and Password not accepted. Learn more at
535 5.7.8  https://support.google.com/mail/?p=BadCredentials je10-20020a170903264a00b001bc2831e1a9sm268100plb.90 - gsmtp
    at SMTPConnection._formatError (C:\Users\anshul\Desktop\full stack expense tracker\node_modules\nodemailer\lib\smtp-connection\index.js:790:19)
    at SMTPConnection._actionAUTHComplete (C:\Users\anshul\Desktop\full stack expense tracker\node_modules\nodemailer\lib\smtp-connection\index.js:1564:34)   
    at SMTPConnection.<anonymous> (C:\Users\anshul\Desktop\full stack expense tracker\node_modules\nodemailer\lib\smtp-connection\index.js:546:26)
    at SMTPConnection._processResponse (C:\Users\anshul\Desktop\full stack expense tracker\node_modules\nodemailer\lib\smtp-connection\index.js:969:20)       
    at SMTPConnection._onData (C:\Users\anshul\Desktop\full stack expense tracker\node_modules\nodemailer\lib\smtp-connection\index.js:755:14)
    at SMTPConnection._onSocketData (C:\Users\anshul\Desktop\full stack expense tracker\node_modules\nodemailer\lib\smtp-connection\index.js:193:44)
    at TLSSocket.emit (node:events:513:28)
    at addChunk (node:internal/streams/readable:324:12)
    at readableAddChunk (node:internal/streams/readable:297:9)
    at Readable.push (node:internal/streams/readable:234:10)
    at TLSWrap.onStreamRead (node:internal/stream_base_commons:190:23) {
  code: 'EAUTH',
  response: '535-5.7.8 Username and Password not accepted. Learn more at\n' +
    '535 5.7.8  https://support.google.com/mail/?p=BadCredentials je10-20020a170903264a00b001bc2831e1a9sm268100plb.90 - gsmtp',
  responseCode: 535,
  command: 'AUTH PLAIN'
}
node.js authentication gmail-api nodemailer errno
1个回答
0
投票

推荐:

确保您使用的 SMTP 服务器是

smtp.gmail.com
并且您通过端口 587(启用 TLS/STARTTLS)或 465(启用 SSL)发送。如果您的 Gmail 帐户启用了两步验证,请继续使用应用程序密码。

参考:

Gmail SMTP 设置

© www.soinside.com 2019 - 2024. All rights reserved.