Skip to content

Instantly share code, notes, and snippets.

@timrichardson
timrichardson / 0_ Gmail API for Service Accounts Python 2.7.
Last active April 28, 2020 19:21
Access gmail via gmail api, Service Account method (applicable if you have Google Apps admin access)
smtp mail sending in cPython blocks the GIL.
This code is tested on python 2.7.8 and I'm using it with web2py
If you use Google Apps for your domain email and if you have admin access, you can easily use the gmail api.
Because you have admin access, you can create a "service account" in the Google Developer Console.
This makes authentication easy.
There are other authorisation methods when you don't have admin access, but they require interaction from the user via a browser.
To use this, you need to install these modules (From PyPI):
pyOpenSSL