question: how to login to gmail smtp from python


I need to send email from python with gmail but
after 30 of may 2022 google blocked auth from less secure apps.

Does anyone know how to login now?

Asked By: Ivan



The best way to login to Gmail SMTP from Python is to use OAuth 2.0 authentication. OAuth 2.0 is a secure authentication protocol that allows users to grant applications access to their data without having to share their username and password. To use OAuth 2.0 authentication with Gmail, you will need to register your application with Google, get the client ID and client secret, and provide the scopes that your application needs to access the user’s data. Once your application is registered, you can use the Google API Client Library for Python to generate an access token and use it to authenticate with Gmail.

Answered By: Pren Ven
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.