I\'m seeking some help logging into a gmail account and downloading some emails using a python script. I\'m trying to adapt an approach found here, but I\'m running into a p
I was able to solve this by using a text-mode browser (elinks) to verify my login from the remote server. I had already struggled a while, so I had already tried enabling unsafe apps and various other incantations.
After logging in to gmail.com in elinks (using the html-only interface and having a security code sent to my phone) I could use imaplib to access the gmail account. Presumably one must do web-authentication from the same IP one tries to use Python/imaplib from.
It's probably Better™ to use the OAuth protocol, but this way I got my script running again without rewriting it.
With the new gmail´s update, some mail servr or apps get blocked due to the new gmails security settings. To solve this, I went to https://www.google.com/settings/security page and 'enabled' Access for less secure apps.
If you want to avoid this error without compromising your account's security, use OAuth to authenticate. The protocol is documented here, and there is Python sample code that shows the use of XOAUTH2 with imaplib.
Independent of this, you should consider enabling two-step verification on your account to make it more secure. If you do, you can use an App Password to connect to IMAP, which might also avoid the above warning.
There are mainly 3 reasons why this error occurs:
You can try to turn on this: https://www.google.com/settings/security/lesssecureapps This action solved the same problem for me.