无法识别节点邮件程序中的错误

Cannot identify error in node mailer

我正在使用节点邮件程序 npm。我一直在研究关于 eduonix 节点 js 课程的教程,并且正在研究 github https://github.com/andris9/Nodemailer 上提供的文档。

我正在尝试完成 TL;DR 用法示例。但是,我找不到从命令行收到的错误。

error  { [Error: Invalid login]
code: 'EAUTH',
response: '535-5.7.8 Username and Password not accepted. Learn more
at\n535 5.7.8 http://support.google.com/mail/bin/answer.py?answer=14257
v3sm2210622igk.1 - gsmtp',
responseCode: 535 }

我已登录到我的 gmail 和 yahoo 帐户。这是我的快递代码。我有

 var nodemailer = require('nodemailer')

sendMail:function(req,res,next){
    // res.send('email coming next');
    var transporter = nodemailer.createTransport({
    service:'Gmail',
    auth: {
        user:'skauyedauty@gmail.com',
        pass:'password'
        }
    });

    var mailOptions = {
        from: 'John Doe <skauyedauty@gmail.com>',
        to: 'skauyedauty@yahoo.com',
        subject:'financing',
        text: 'You have a new submission with the following details...Name: '+req.body.name + 'email: '+ req.body.email + 'message: '+req.body.message
        html: '<p>You got a new submission with the following details </p><ul><li>Name: '+req.body.name + '</li><li>Email: '+req.body.email + '</li><li>message: ' + req.body.message + "</li></ul>"
    };
    transporter.sendMail(mailOptions,function(error,info){
        if(error){
            console.log('error ',error);
            res.redirect('/')
        } else{
            console.log('Message sent: ' +info.response);
            res.redirect('/');
        }
    });



};

在我的 html 中,这是我的表单,我确保为每个输入添加名称,并在表单中调用 post 方法。

<form class="form-horizontal" action="/send" method="post">
          <div class="form-group">
            <label for="inputEmail3" class="col-sm-2 control-label">Name</label>
            <div class="col-sm-10">
              <input type="text" name="name"class="form-control" id="name" placeholder="Name">
            </div>            
          </div>

          <div class="form-group">
            <label for="inputEmail3" class="col-sm-2 control-label">Email</label>
            <div class="col-sm-10">
              <input type="email" class="form-control" id="inputEmail3" placeholder="Email">
            </div>            
          </div>

          <div class="form-group">
            <label for="phoneNumber" class="col-sm-2 control-label">Phone Number</label>
            <div class="col-sm-10">
              <input type="text" name="phoneNumber"class="form-control" id="inputPassword3" placeholder="PhoneNumber">
            </div>
          </div>

          <div class="form-group">
            <label for="message" class="col-sm-2 control-label">Message</label>
            <div class="col-sm-10">
              <input type="text" name="message"class="form-control" id="message" placeholder="message">
            </div>
          </div>
          <div class="form-group">
            <div class="col-sm-offset-2 col-sm-10">
              <button type="submit" class="btn btn-default">Submit</button>
            </div>
          </div>





        </form>

Gmail 阻止从除其网络应用程序以外的任何地方登录。

The nodemailer docs explain this issue and how to resolve it.

基本上在您的帐户上启用 Less secure apps

Using Gmail

Even though Gmail is the fastest way to get started with sending emails, it is by no means a preferable solution unless you are using OAuth2 authentication. Gmail expects the user to be an actual user not a robot so it runs a lot of heuristics for every login attempt and blocks anything that looks suspicious to defend the user from account hijacking attempts. For example you might run into trouble if your server is in another geographical location – everything works in your dev machine but messages are blocked in production.

Additionally Gmail has came up with the concept of 'less secure' apps which is basically anyone who uses plain password to login to Gmail, so you might end up in a situation where one username can send (support for 'less secure' apps is enabled) but other is blocked (support for 'less secure' apps is disabled).

To prevent having login issues you should either use XOAUTH2 (see details here) or use another provider and preferably a dedicated one like Mailgun or SendGrid or any other. Usually these providers have free plans available that are compareable to the daily sending limits of Gmail. Gmail has a limit of 500 recipients a day (a message with one To and one Cc address counts as two messages since it has two recipients) for @gmail.com addresses and 2000 for Google Apps customers, larger SMTP providers usually offer about 200-300 recipients a day for free.