LinkedInTwitterFacebook

Using python to make authentication into GMail API.

Is simple to do with python. The script I make is simple without classes.
Let’s start with first steps:
You need to create your project and then one credential with json file.
See the next image to see how is your json file. My json file is renamed to client_secret.json and is used by python script.
python-oauth2
The json file is into same folder with my python script.
After first run the script will make one json file named: gmail-python-quickstart.json.
Is simple way to get and put credentials to solve authentification to google.
Another step is to add GMail API library to your project. This allow you to use the functions from the GMail API.
The python script is very simple to do. Follow the part of this script.
Is need to use some python modules. One reason is to deal with email format, see email python module.
Some python modules are used to make authentication to google: oauth2client and apiclient.
I used argparse python module , but is no need to add arguments to the script.
The result of this script will send a email to: your@yahoo.com.
The email is created by CreateMessage function.
About the special value “me” that come from Google API and is for user.

Share