【问题标题】:nodejs -nodemailer cannot send email after allowing less secure apps accessnodejs -nodemailer 在允许不太安全的应用程序访问后无法发送电子邮件
【发布时间】:2023-03-24 08:32:01
【问题描述】:

这是我第一次使用 nodejs 和 nodemailer 从我拥有的虚拟帐户发送电子邮件。尝试发送电子邮件时出现错误

"  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 w17sm3259346ejk.112 - gsmtp',
  responseCode: 535,
  command: 'AUTH PLAIN'"

我的凭据是正确的,并且我已启用从不太安全的应用程序访问我的 gmail 帐户。我还尝试从我的用户中删除 @gmail.com,但我仍然收到相同的错误。

我的代码:

const mailer = require('nodemailer');

const  transporter = mailer.createTransport({
  service: 'gmail',
  port:587,
  auth: {
    user: 'test@gmail.com',
    pass: 'my pass '
  }
});

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



function sendEmail(){

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

module.exports = {sendEmail}; 

非常感谢您的帮助。请不要将其标记为重复,因为我已经在这里搜索过。

【问题讨论】:

    标签: node.js smtp nodemailer


    【解决方案1】:

    收件人的邮件也应该启用不太安全的应用程序。否则您的邮件将无法到达目的地。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-08
      • 1970-01-01
      • 2020-05-30
      • 1970-01-01
      • 2022-06-11
      • 2020-04-17
      相关资源
      最近更新 更多