mscdex / node-imap

An IMAP client module for node.js.
MIT License
2.17k stars 382 forks source link

Authentication with gmail #845

Closed Ramsteven closed 3 years ago

Ramsteven commented 3 years ago

hello, I am having this below error, when trying to authenticate to Gmail, with the first example code:


 { Error: Invalid credentials (Failure)
    at Connection._resTagged (/home/ramsteven/projecto/node_modules/imap/lib/Connection.js:1502:11)
    at Parser.<anonymous> (/home/ramsteven/projecto/node_modules/imap/lib/Connection.js:194:10)
    at Parser.emit (events.js:198:13)
    at Parser._resTagged (/home/ramsteven/projecto/node_modules/imap/lib/Parser.js:175:10)
    at Parser._parse (/home/ramsteven/projecto/node_modules/imap/lib/Parser.js:139:16)
    at Parser._tryread (/home/ramsteven/projecto/node_modules/imap/lib/Parser.js:82:15)
    at TLSSocket.Parser._cbReadable (/home/ramsteven/projecto/node_modules/imap/lib/Parser.js:53:12)
    at TLSSocket.emit (events.js:198:13)
    at emitReadable_ (_stream_readable.js:555:12)
    at process._tickCallback (internal/process/next_tick.js:63:19)
  type: 'no',
  textCode: 'AUTHENTICATIONFAILED',
  source: 'authentication' }
Connection ended
mscdex commented 3 years ago

My guess is wrong login/password or 2FA is required.

Ramsteven commented 3 years ago

the data is well, but I had to change the unsecured application access from Gmail then I could sign_in from Node, this could be very insecure, exist another better way to get the authentication with had to change the password?

mscdex commented 3 years ago

Yes, use 2FA instead of a plain password. See the xoauth2 config option in the readme.

Bec-k commented 3 years ago

Will save some time for others devs. You have to go to security settings in gmail and turn switcher to allow connections to IMAP server. Go to https://myaccount.google.com/ Go to Security section on the left navigation panel. Find Less secure app access block, it is somewhere below, scroll to it. Turn it to ON

P.S. and you have to enable IMAP in gmail settings in Forwarding and POP/IMAP section, which is here: https://mail.google.com/mail/u/1/#settings/fwdandpop

Guess it worth to add that into main README.

Btw great module, ty ppl. Lacking async/await, but it work flawlessly.

ngochoaitn commented 1 year ago

Now you must use app password instead of Less secure app access: https://support.google.com/accounts/answer/185833