4
votes

So i have the following codes:

const nodemailer = require("nodemailer");

const mailer = {
    service: "gmail",
    auth: {
        type: "OAuth2",
        user: "[email protected]",
        clientId: "123123123123123123123123123123.apps.googleusercontent.com",
        clientSecret: "krW123123123123123123RqEnS",
        refreshToken: "1/SM-7f31231231231231231231231231231231231231231231231UzH",
        accessToken: "ya29.1234568791231324564897894231324564697897ss3Ggi-TkWO4HSIZBqHiLpoIkT7H_Sgii4RQxyVJ0QjIfjKB5zk"
    }
}

const transporter = nodemailer.createTransport(mailer);
transporter.sendMail({
    to: "[email protected]",
    subject: "test",
    text: "test"
});

But when i try to send email, it always give error as follow: 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 f67-v6sm75536287pfe.75 - gsmtp

This is the full trace:

(node:25324) UnhandledPromiseRejectionWarning: 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 f67-v6sm75536287pfe.75 - gsmtp
    at SMTPConnection._formatError (D:\Sources\NodeJS\test\node_modules\nodemailer\lib\smtp-connection\index.js:606:19)
    at SMTPConnection._actionAUTHComplete (D:\Sources\NodeJS\test\node_modules\nodemailer\lib\smtp-connection\index.js:1335:34)
    at SMTPConnection._responseActions.push.str (D:\Sources\NodeJS\test\node_modules\nodemailer\lib\smtp-connection\index.js:1314:26)
    at SMTPConnection._processResponse (D:\Sources\NodeJS\test\node_modules\nodemailer\lib\smtp-connection\index.js:762:20)
    at SMTPConnection._onData (D:\Sources\NodeJS\test\node_modules\nodemailer\lib\smtp-connection\index.js:558:14)
    at TLSSocket._socket.on.chunk (D:\Sources\NodeJS\test\node_modules\nodemailer\lib\smtp-connection\index.js:510:47)
    at TLSSocket.emit (events.js:182:13)
    at addChunk (_stream_readable.js:283:12)
    at readableAddChunk (_stream_readable.js:264:11)
    at TLSSocket.Readable.push (_stream_readable.js:219:10)

Any idea what happened and how to fix this? Thank you.

2

2 Answers

1
votes

Do following changes.I hope this will help you.This error occurs when you are trying to access google account and forget to switch on google less security option.

https://myaccount.google.com/lesssecureapps?utm_source=google-account&utm_medium=web

0
votes

I don't know if the credentials you entered above are the actual ones, but the formatting of the access token, client ID, etc. looks valid.

NEVER post your actual credentials on the internet! You basically just posted your username and password on the internet.