gmail login failure using python and imaplib
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.
You can try to turn on this: https://www.google.com/settings/security/lesssecureapps This action solved the same problem for me.
There are mainly 3 reasons why this error occurs:
- Internet Connection Issue
- Incorrect Login Credentials
- myaccount.google.com/lesssecureapps is turned off
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.