Skip to content Skip to sidebar Skip to footer

I Encounter An Authenticationfailed Error When Connecting To Email With Imaplib Library

How can I connect to imaplib library without encountering AUTHENTICATIONFAILE error !? My Gmail inbox shows me a serious security alert (login attempt blocked) when logging in thro

Solution 1:

This is most likely gmail blocking "less secure apps" from connecting to your account. This blocking is enabled, by default.

From a google support page:

You can block sign-in attempts from some apps or devices that are less secure. Apps that are less secure don't use modern security standards, such as OAuth. Using apps and devices that don’t use modern security standards increases the risk of accounts being compromised. Blocking these apps and devices helps keep your users and data safe.

If you would like to turn on access to less secure apps (which will make your account more vulnerable to being attacked), then you can follow these steps:

  1. Sign into your google account normally. (https://myaccount.google.com/)

  2. Once signed in, go to the "Security" page.

  3. Scroll down until you see a window with "Less secure app access". If you want to access your email using python code like you posted, this needs to be turned on.

Personally, I think this is acceptable on a throwaway/testing account but I would never do this to my main/personal account or any account involving communicating with clients.

In fact, take a look at this page: https://developers.google.com/gmail/api/quickstart/python Gmail has a dedicated API for connecting to your google mail account. Their api implements proper security measures which means you won't need to enable less secure app access... protecting your account!

Post a Comment for "I Encounter An Authenticationfailed Error When Connecting To Email With Imaplib Library"