I am trying to send email through nodemailer but is not able to send email and showing following error.
{ [Error: Invalid login]
code: \'E
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.