Nodemailer is not able send mail using gmail

前端 未结 3 981
盖世英雄少女心
盖世英雄少女心 2021-01-12 22:08

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

{ [Error: Invalid login]
  code: \'E         


        
相关标签:
3条回答
  • 2021-01-12 22:33

    UPDATE

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


    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 }
    }));
    

    See https://github.com/andris9/nodemailer-smtp-transport#authentication.

    0 讨论(0)
  • 2021-01-12 22:35
    var transporter = nodemailer.createTransport({
        service: 'Gmail',
        auth: {
           user: 'username',
           pass: 'password'
        }
    });
    

    Instead of username = enter your valid email id and password = your password

    again an alert shows to your Gmail from google like

    (Google will continue to block sign-in attempts from the app you're using because it has known security problems or is out of date. You can continue to use this app by allowing access to less secure apps, but this may leave your account vulnerable. )

    you need to allow the access from other mailer

    then it generates the response

    0 讨论(0)
  • 2021-01-12 22:50

    You may need to "Allow Less Secure Apps" in your gmail account (it's all the way at the bottom). You also may need to "Allow access to your Google account". See details about using Gmail here.

    Above solution worked for me which I found on github. Here's the link.

    0 讨论(0)
提交回复
热议问题