Skip to content

Installation

Jeremy Ephron Barenholtz edited this page Sep 13, 2020 · 1 revision

Simple Gmail requires Python 3.6 or greater and some setup within Google's services to allow your application to access your gmail account.

Setup a Google API Credential

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),

  1. 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).

  2. Click on the "Dashboard" tab, then "Enable APIs and Services". Search for Gmail and enable.

  3. Click on the Credentials tab, then "Create Credentials" > "OAuth client ID".

  4. Select what kind of application this is for, and give it a memorable name.

  5. Back on the credentials screen, click the download icon next to the credential you just created to download it as a JSON object.

  6. 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.

Install Simple Gmail

You can install Simple Gmail with pip:

python3 -m pip install simplegmail
Clone this wiki locally