+ 2

NodemailerError - Invalid login: 535-5.7.8 Username and Password not accepted

I've been trying to setup a simple OTP verification system on my webpage using Nodemailer module, the whole code is a bit long, so here is a reproducible example, [server.js] ````````````````````````````````````````````````````````````````````` let nm = require('nodemailer'); let trans = nm.createTransport({ host: 'smtp.gmail.com', port: 465, secure: true, // use SSL auth: { user: '<[email protected]>', pass: '<mypassword>' } }); let details = { from: '<[email protected]>', to: '<[email protected]>', subject: 'Heading', html: 'Some content' }; trans.sendMail(details, console.log); // one-liner handling ```````````````````````````````````````````````````````````````````` The above code outputs the following error: ----------------------------------------------------------------------------------- > Error: Invalid login: 535-5.7.8 Username and Password not accepted. ..... code: 'EAUTH', ..... command: 'AUTH PLAIN' ------------------------------------------------------------------------------------- I've tried changing my `transport` as per the article at https://www.w3schools.com/nodejs/nodejs_email.asp, `````````````````````````````````````````````````` let trans = nm.createTransport({ service: 'Gmail', // also tried 'gmail' auth: { user: '<[email protected]>', pass: '<mypassword>' } }); `````````````````````````````````````````````````` But, it results in the same error. How to fix it? > Note: I've enabled "Access for less secure apps" in my gmail, and I don't have two-step verification turned on. Also, I'm using Windows 10, Node v10.x, Nodemailer v6.x. Please note that, I'm using www.sololearn.com :)

13th May 2020, 8:09 AM
777 - avatar
1 Answer
Gmail server normally blocked access if the server is far away from your location. Better use smtp email or email api provided by services like sendGrid
22nd May 2020, 11:19 PM
Calviղ - avatar