mscdex / node-imap

An IMAP client module for node.js.
MIT License
2.14k stars 379 forks source link

gmail disabled "Less secure apps" since May 30, 2022 #879

Closed cscan closed 2 years ago

cscan commented 2 years ago

Is there any workaround to deal with the gmail imap login after May 30? I use the following code to login but fail since Jun.

    gmail = new Imap({
        user: ini.user,
        password: ini.password,
        host: 'imap.gmail.com',
        port: 993,
        tls: true,
        authTimeout: 100000,
        tlsOptions: {
            rejectUnauthorized: false
        }
    })
    gmail.once('error', terminate)

    await gmail.connect()

It shows the error:

Error: Invalid credentials (Failure)
    at Connection._resTagged (/Users/can/nodejs/imap/node_modules/imap/lib/Connection.js:1502:11)
    at Parser.<anonymous> (/Users/can/nodejs/imap/node_modules/imap/lib/Connection.js:194:10)
    at Parser.emit (events.js:315:20)
    at Parser._resTagged (/Users/can/nodejs/imap/node_modules/imap/lib/Parser.js:175:10)
    at Parser._parse (/Users/can/nodejs/imap/node_modules/imap/lib/Parser.js:139:16)
    at Parser._tryread (/Users/can/nodejs/imap/node_modules/imap/lib/Parser.js:82:15)
    at TLSSocket.Parser._cbReadable (/Users/can/nodejs/imap/node_modules/imap/lib/Parser.js:53:12)

Google suggests to use OAuth, but I was stuck in their messy app creation procedures.

cscan commented 2 years ago

I found a workaround by creating app password, without changing any codes. Please refer to this video: https://www.youtube.com/watch?v=uVDq4VOBMNM

LordJohn42 commented 2 years ago

Thank you man!