Nodemailer不能使用gmail发送邮件 [英] Nodemailer is not able send mail using gmail

查看:418
本文介绍了Nodemailer不能使用gmail发送邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过 nodemailer 发送电子邮件,但无法发送电子邮件并显示以下错误。

I am trying to send email through nodemailer but is not able to send email and showing following error.

{ [Error: Invalid login]
  code: 'EAUTH',
  response: '534-5.7.14 <https://accounts.google.com/ContinueSignIn?sarp=1&scc=1&plt=AKgnsbsTr\n534-5.7.14 2r0PE8hXz57GMK9aydA3GouUGQr1Pc2wBywEf6i09kKVOv9Qv5y9Csy_lL-PIgUO6ML8uA\n534-5.7.14 ZsEiEkpAU0N5aiQBZdI1urKo3XfCiiS2MhjiUZaBgpn88sFXR-sBeA5ydMc_Md1F5wDcbX\n534-5.7.14 7ynrcVC-h0H_-e_ptvGhA3ywiHOSoDZAxzrindvEMNkXmCilbo9J7ITdlXFKwQjITaIkei\n534-5.7.14 Tk8QMKEY22ldNjE78Lh2ekheLd5M> Please log in via your web browser and\n534-5.7.14 then try again.\n534-5.7.14  Learn more at\n534 5.7.14  https://support.google.com/mail/answer/78754 21sm9309692qgj.21 - gsmtp',
  responseCode: 534 }

我正在使用确切的代码显示在nodemailer文档中。

I am using exact code as shown in nodemailer documentation.

这是我正在使用的服务器端代码。

this is server side code which i am using.

var transporter = nodemailer.createTransport({
    service: 'Gmail',
    auth: {
       user: 'username',
       pass: 'password'
    }
});

app.post('/sendfeedbackmail', function(req, res) {

    var mailOptions = {
        from: 'Feedback<username@gmail.com>', // sender address 
        to: 'user1@gmail.com', // receiver 
        subject: 'Subject', // Subject line 
        text: mailData, // plaintext body 
        html: mailData // html body 
    };

   // send mail with defined transport object 
   transporter.sendMail(mailOptions, function(error, info) {
       if (error) {
          console.log(error);
          res.send({success:false});
       }else{
           res.send({
              success: true
           })
       }
   });
})

这几天前工作正常,对其他电子邮件客户端仍然工作正常,因此我认为问题可能与gmail帐户的任何安全设置有关。

This was working fine few days ago and still working fine for other email client then gmail hence i think the issue may be related to any security setting of gmail account.

推荐答案

更新



检查 http://masashi-k.blogspot.com.br/2013/06/sending-mail-with-gmail-using-xoauth2.html 注册您的应用程序。

UPDATE

Check http://masashi-k.blogspot.com.br/2013/06/sending-mail-with-gmail-using-xoauth2.html to register your application.

您需要这样的信息才能在Gmail上进行身份验证:

You will need something like this to authenticate on Gmail:

var xoauth2 = require('xoauth2');
var nodemailer = require('nodemailer');
var smtp = require('nodemailer-smtp-transport');

var generator = xoauth2.createXOAuth2Generator({
  user: '..',
  clientId: '...',
  clientSecret: '...',
  refreshToken: '...',
  accessToken: ''
});
generator.on('token', function(token){
  console.info('new token', token.accessToken);
  // maybe you want to store this token
});

var transporter_google = nodemailer.createTransport(smtp({
  name: '...',
  host: '...',
  port: 587,
  secure: false,
  ignoreTLS: false,
  tls: { rejectUnauthorized: true },
  debug: false,
  auth: { xoauth2: generator }
}));

请参阅 https://github.com/andris9/nodemailer-smtp-transport#authentication

这篇关于Nodemailer不能使用gmail发送邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆