-
-
Notifications
You must be signed in to change notification settings - Fork 76
Installation
Simple Gmail requires Python 3.6 or greater and some setup within Google's services to allow your application to access your gmail account.
The only setup required is to download an OAuth 2.0 Client ID file from Google that will authorize your application.
This can be done at: https://console.developers.google.com/apis/credentials. For those who haven't created a credential for Google's API, after clicking the link above (and logging in to the appropriate account),
-
Select/create the project that this authentication is for (if creating a new project make sure to configure the OAuth consent screen; you only need to set an Application name).
-
Click on the "Dashboard" tab, then "Enable APIs and Services". Search for Gmail and enable.
-
Click on the Credentials tab, then "Create Credentials" > "OAuth client ID".
-
Select what kind of application this is for, and give it a memorable name.
-
Back on the credentials screen, click the download icon next to the credential you just created to download it as a JSON object.
-
Save this file as "client_secret.json" and place it in the root directory of your application. (The
Gmail
class takes in an argument for the name of this file if you choose to name it otherwise.)
The first time you create a new instance of the Gmail
class, a browser window
will open, and you'll be asked to give permissions to the application. This
will save an access token in a file named "gmail-token.json", and only needs to
occur once.
You are now good to go!
Note about authentication method: I have opted not to use a username-password authentication (through imap/smtp) since using Google's authorization is both significantly safer and avoids clashing with Google's many security measures, which require extra steps to disable.
You can install Simple Gmail with pip
:
python3 -m pip install simplegmail
If you have any questions, comments, or suggestions, feel free to open an issue or submit a pull request with your changes.