Nodejs 节点邮件程序错误

Nodejs nodemailer error

运行 Nodemailer 出现如下错误,请问我该如何解决?

Error: Missing credentials for "PLAIN" at SMTPConnection._formatError

var nodemailer=require('nodemailer');
var transporter = nodemailer.createTransport({
    service:'Gmail',
    auth:{
        user:'kumaresankeerthy@gmail.com',
        password:'9943886854**'
    }
});
var mailOptions={

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

您需要以不同方式设置传输器,使用真实 Google 帐户的实际电子邮件和密码。

// create reusable transporter object using the default SMTP transport
let transporter = nodemailer.createTransport({
    service: 'gmail',
    auth: {
        user: 'somerealemailaddress@gmail.com', //email address to send from
        pass: 'somerealemailpassword' //the actual password for that account
    }
});

您在构造函数中提供了错误的参数。它 pass 不是 password

根据official docs

let transporter = nodemailer.createTransport({
    host: 'smtp.ethereal.email',
    port: 587,
    secure: false, // true for 465, false for other ports
    auth: {
        user: account.user, // generated ethereal user
        pass: account.pass // generated ethereal password
    }
});
  • 通过转到以下 url 解决了这个问题(同时使用我要发送邮件的帐户连接到 google):

https://www.google.com/settings/security/lesssecureapps* 您在 gmail 中启用了安全性较低的应用程序,之后它会;工作