Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid credentials (Failure) - Gmail #901

Open
ghost opened this issue Jun 2, 2023 · 12 comments
Open

Invalid credentials (Failure) - Gmail #901

ghost opened this issue Jun 2, 2023 · 12 comments

Comments

@ghost
Copy link

ghost commented Jun 2, 2023

Good morning,

could you help me, I am not able to connect to the gmail server, below the code.

describe('Check connection to email server', function () {

it('It should return a successful connection message', async function () {

    var config = {
        user: '[email protected]',
        password: 'xxxxxx',
        host: 'imap.gmail.com',
        port: 993,
        tls: true,
    };
    
    async function checkEmailConnection() {
        const imap = new Imap(config);
    
        return new Promise((resolve, reject) => {
            imap.once('ready', () => {
                imap.end();
                resolve('Conexão bem-sucedida com o servidor de e-mail!');
            });
    
            imap.once('error', (error) => {
                reject(`Erro na conexão com o servidor de e-mail: ${error}`);
            });
    
            imap.connect();
        });
    }

    const message = await checkEmailConnection();
})

})

after executing the error is returned
thrown: "Erro na conexão com o servidor de e-mail: Error: Invalid credentials (Failure)"

thank you very much

@mscdex
Copy link
Owner

mscdex commented Jun 2, 2023

Perhaps you need to use the xoauth2 config setting for OAuth 2-based authentication instead of using a password.

@ghost
Copy link
Author

ghost commented Jun 2, 2023

@mscdex I did the configuration, but now it is showing another error:

this is the code
const credentials = {
client_id: 'xxx',
client_secret: 'xxx',
redirect_uri: 'http://localhost',
};

    const oauth2Client = new google.auth.OAuth2(
        credentials.client_id,
        credentials.client_secret,
        credentials.redirect_uri
    );

    const auth = {
        user: '[email protected]',
        xoauth2: oauth2Client,
    };

    const imap = new Imap({
        user: auth.user,
        xoauth2: oauth2Client,
        host: 'imap.gmail.com',
        port: 993,
        tls: true,
        authTimeout: 30000,
        tlsOptions: {servername: 'imap.gmail.com', rejectUnauthorized: false,}
    });

    function openInbox(cb) {
        imap.openBox('INBOX', true, cb);
    }

    async function checkEmailConnection() {
        imap.connect();
    }

    await checkEmailConnection()

this is the error

return str.replace(RE_BACKSLASH, '\\').replace(RE_DBLQUOTE, '\"');
^

TypeError: str.replace is not a function
at escape (C:\aqa-argopay-api\node_modules\imap\lib\Connection.js:1804:14)
at Connection. (C:\aqa-argopay-api\node_modules\imap\lib\Connection.js:1672:24)
at Connection.Object..Connection._resTagged (C:\aqa-argopay-api\node_modules\imap\lib\Connection.js:1535:22)
at Parser. (C:\aqa-argopay-api\node_modules\imap\lib\Connection.js:194:10)
at Parser.emit (node:events:527:28)
at Parser.Object..Parser._resTagged (C:\aqa-argopay-api\node_modules\imap\lib\Parser.js:175:10)
at Parser.Object..Parser._parse (C:\aqa-argopay-api\node_modules\imap\lib\Parser.js:139:16)
at Parser.Object..Parser._tryread (C:\aqa-argopay-api\node_modules\imap\lib\Parser.js:82:15)
at TLSSocket.Parser.cbReadable (C:\aqa-argopay-api\node_modules\imap\lib\Parser.js:53:12)
at TLSSocket.emit (node:events:527:28)
at emitReadable
(node:internal/streams/readable:578:12)
at processTicksAndRejections (node:internal/process/task_queues:82:21)

@zhyd1997
Copy link

same issue

@zhyd1997
Copy link

zhyd1997 commented Jul 1, 2023

Try to use app password, works for me: https://support.google.com/accounts/answer/185833

Screenshot 2023-07-01 at 12 13 41

@Vastradamus
Copy link

Hey all, I seem to have the same problem. Has anyone managed to find a workaround?

@LukasLewandowski
Copy link

You need 2FA and App password :)

#879

@Vastradamus
Copy link

That's what I tried first, but I was getting this:
Error: No supported authentication method(s) available. Unable to login.

So I assumed I need to use xoauth2. Is there something I'm missing?

@LukasLewandowski
Copy link

@Vastradamus It worked for me, with 2FA and password

var imap = new Imap({ user: '', password: '', host: 'imap.gmail.com', port: 993, tls: true, authTimeout: 100000, tlsOptions: { rejectUnauthorized: false, servername: 'imap.gmail.com' }, });

@QA1980
Copy link

QA1980 commented Oct 31, 2023

@Vastradamus I was dealing with Invalid credential error but I was able to make it work using App password.An app password is a 16-digit passcode that gives a less secure app or device permission to access your Google Account.
Here is the link how to set up the password https://support.google.com/mail/answer/185833?hl=en
Finally, replace the generated password in the email config password.

@yracnet
Copy link

yracnet commented Feb 6, 2024

I have resolved this error in 2 step:

  • IMAP Enabled from "Email Setting"
  • Less secure app access Enabled from "Google Account"

@YangYgYang
Copy link

I have resolved this error in 2 step:

  • IMAP Enabled from "Email Setting"
  • Less secure app access Enabled from "Google Account"

This feature appears to have been discontinued by Google.

@Saksham-Chauhan
Copy link

Saksham-Chauhan commented Aug 12, 2024

This has been verified by me that the feature have been or maybe discontinued by Google See this
Please close this issue.

However, I believe this can be fixed by creating a service account and connecting to it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants