我收到错误消息“{ 错误:登录无效:535-5.7.8 用户名和密码不被接受。” 当我尝试从 Node JS 发送带有模块 nodemailer 的邮件时

9 email smtp login node.js

我是 Node js 的新手,我尝试向其他电子邮件发送类似示例的消息,当我从 linux 在终端中运行该文件时,出现此错误:

root@me:/home/memee/Desktop/test/NodeJS/mail# nano example.js
root@me:/home/memee/Desktop/test/NodeJS/mail# node example.js
{ 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 77-v6sm41437784pga.40 - gsmtp
    at SMTPConnection._formatError (/home/memee/Desktop/test/NodeJS/mail/node_modules/nodemailer/lib/smtp-connection/index.js:606:19)
    at SMTPConnection._actionAUTHComplete (/home/memee/Desktop/test/NodeJS/mail/node_modules/nodemailer/lib/smtp-connection/index.js:1335:34)
    at SMTPConnection._responseActions.push.str (/home/memee/Desktop/test/NodeJS/mail/node_modules/nodemailer/lib/smtp-connection/index.js:366:26)
    at SMTPConnection._processResponse (/home/memee/Desktop/test/NodeJS/mail/node_modules/nodemailer/lib/smtp-connection/index.js:762:20)
    at SMTPConnection._onData (/home/memee/Desktop/test/NodeJS/mail/node_modules/nodemailer/lib/smtp-connection/index.js:558:14)
    at TLSSocket._socket.on.chunk (/home/memee/Desktop/test/NodeJS/mail/node_modules/nodemailer/lib/smtp-connection/index.js:510:47)
    at emitOne (events.js:116:13)
    at TLSSocket.emit (events.js:211:7)
    at addChunk (_stream_readable.js:263:12)
    at readableAddChunk (_stream_readable.js:250:11)
  code: 'EAUTH',
  response: '535-5.7.8 Username and Password not accepted. Learn more at\n535 5.7.8  https://support.google.com/mail/?p=BadCredentials 77-v6sm41437784pga.40 - gsmtp',
  responseCode: 535,
  command: 'AUTH PLAIN' }
Run Code Online (Sandbox Code Playgroud)

我知道我的错误是登录,但我的密码和电子邮件是正确的。

我的代码:

var nodemailer = require('nodemailer');

var transporter = nodemailer.createTransport({
  service: 'gmail',
  auth: {
    user: 'example@gmail.com',
    pass: 'here I put my password'
  }
});

var mailOptions = {
  from: 'from@gmail.com',
  to: 'to@gmail.com',
  subject: 'Sending Email using Node.js',
  text: 'That was easy!'
};

transporter.sendMail(mailOptions, function(error, info){
  if (error) {
    console.log(error);
  } else {
    console.log('Email sent: ' + info.response);
  }
});
Run Code Online (Sandbox Code Playgroud)

我的 node 和 npm 版本:

root@me:~# node --version
v8.11.3
root@me:~# npm --v
6.1.0
root@me:~# 
Run Code Online (Sandbox Code Playgroud)

我用过这个教程:教程

Ric*_*d A 16

我最近遇到了这个问题,它与帐户上的安全性较低的应用程序设置有关。

选择“允许用户管理他们对不太安全的应用程序的访问”修复了它。

在此处输入图片说明


m9m*_*m9m 5

https://www.google.com/settings/security/lesssecureapps打开允许不太安全的应用程序


kar*_*agi 5

我之前也遇到过同样的问题,但从用户名中删除'@gmail.com'后对我来说效果很好。
错误'535-5.7.8 Username and Password not accepted'仅在以下提到的情况下发生:

  1. 错误的凭据。
  2. 添加@gmail.com用户名,避免它!
  3. 启用两因素身份验证。如果是,则禁用它。
  4. https://myaccount.google.com/lesssecureapps如果关闭,请将其打开以启用 lesssecureapps。


jms*_*ido 2

您的电子邮件和密码不匹配,请查看错误消息:response: '535-5.7.8 Username and Password not accepted.

请参阅您的代码的这一部分:

var transporter = nodemailer.createTransport({
  service: 'gmail',
  auth: {
    user: 'example@gmail.com', // here use your real email
    pass: 'here I put my password' // put your password correctly (not in this question please)
  }
});
Run Code Online (Sandbox Code Playgroud)

如果您使用用户名和密码登录,您将能够发送电子邮件。

我使用相同的代码发送此电子邮件,但使用了我的凭据: 我使用相同的代码发送此电子邮件