简体   繁体   中英

Error: Invalid login: nodeMailer when everything look great

Got an error I put on less app option on Gmail I do not have 2fa my credential I perfect and I can log them in my file to see that's my file read it well but still got this error.

 const nodemailer = require("nodemailer"); const smtpTransport = require("nodemailer-smtp-transport"); require("dotenv").config(); console.log(process.env.MAIL); let transporter = nodemailer.createTransport( smtpTransport({ service: "Gmail", host: "smtp.gmail.com", auth: { user: process.env.EMAIL, pass: process.env.PASSWORD, }, }) ); // do it reactively the to let mailOptions = { from: process.env.EMAIL, to: "ethan.sayagh@gmail.com", subject: "Congrat you bought x amout", text: "Made by ethanolle", }; transporter.sendMail(mailOptions, function (err, data) { if (err) { logger.info(`Invalid Mail sent`); console.log(err); } else { console.log("emailsent"); } });
The Error:

Error: Invalid login: 535-5.7.8 Username and Password not accepted.

For some reason even I had been experiencing this problem, even after enabling "allow less secure apps" Google seems to be blocking sign in attempts.

A workaround I found was to use app passwords , be highly cautious though, because anyone can sign in without restriction if they have your app password.

Note that you'll need to have two factor authentication enabled, you can set up an app password here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM