0

I am trying to use imaplib in order to fetch my mails

import imaplib
mail= imaplib.IMAP4_SSL("imap.gmail.com")
mail.login("mymailaddress","mypassword")
mail.select("inbox")

but unfortunately, I am getting the following error

 File , line 3, in <module>
    mail.login("mymailaddress","mypassword")
    raise self.error(dat[-1])
imaplib.error: b'[ALERT] Application-specific password required: https://support.google.com/accounts/answer/185833 (Failure)'

I have checked all other suggestion given on similar question but none are working (similar problem). I even enabled IMAP on my account. I also allow less secure app. What might be the reason for this error?

halfer
  • 19,824
  • 17
  • 99
  • 186
Harsh Goyal
  • 11
  • 1
  • 2

2 Answers2

2

As stated in the error message you are getting You need to go to Sign in with App Passwords

The issue you are having is that you are using the users password. You should be using an apps password

enter image description here

Side note: Update as of May 30, 2022

To help keep your account secure, starting May 30, 2022, ​​Google will no longer support the use of third-party apps or devices which ask you to sign in to your Google Account using only your username and password.

This means anyone connecting to the smtp / imap server and using the users password will get an error. Less secure apps will no work anymore.

You need to switch to using xoauth2 or trying an apps password. At this time it is not clear if apps password will work or not.

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
0

At this time it is not clear if apps password will work or not.

I was able to set up apps password today following an article in the google help center

lubo
  • 3
  • 4
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jun 07 '22 at 19:34