node-imap
node-imap copied to clipboard
Invalid credentials (Failure) - Gmail
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
Perhaps you need to use the xoauth2
config setting for OAuth 2-based authentication instead of using a password.
@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.
same issue
Try to use app password, works for me: https://support.google.com/accounts/answer/185833
Hey all, I seem to have the same problem. Has anyone managed to find a workaround?
You need 2FA and App password
:)
https://github.com/mscdex/node-imap/issues/879
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?
@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' }, });
@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.
I have resolved this error in 2 step:
- IMAP Enabled from "Email Setting"
- Less secure app access Enabled from "Google Account"
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.
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.