I am using nodemailer to send token to email (gmail smtp) but I'm getting this error:
Error: Invalid login: 535-5.7.8 Username and Password not accepted. Learn more at 535 5.7.8 https://support.google.com/mail/?p=BadCredentials v185sm51735194pfb.14 - gsmtp
Im using seperate file to secure my email address and password which is secret.js below is my code.
module.exports = {
auth:{
user: 'myrealemail@gmail.com',
pass: 'myrealpassword',
}
}
below is the code for user.js
var User = require('../models/user');
var secret = require('../secret/secret');
function(rand, callback){
User.findOne({'email':req.body.email}, (err, user) => {
if(!user){
req.flash('error', 'No account exist or email is invalid');
return res.redirect('/forgot');
}
// Set random token
user.passwordResetToken = rand;
user.passwordResetExpires = Date.now() + 60*60*1000;
user.save((err) => {
callback(err, rand, user)
});
})
},
//sending token to users email
function(rand, user, callback){
var smtpTransport = nodemailer.createTransport({
service: 'Gmail',
auth: {
user: secret.auth.user,
pass: secret.auth.pass
}
});