Send an email with Gmail and Python, use OAuth flow
Use the OAuth flow to sign into your Gmail account in the browser and then do requests using a token, so that your Gmail password does not have to be entered in a config file or stored somewhere on your machine.
Also, once you authenticate the first time, your credentials will be cached for future runs.
- Make sure to follow the step to enable API for Gmail and download a JSON file.
- Clone the project.
- Install Python.
- Install dependencies in virtual environment.
$ pip install requirements.txt
- Run the script.
$ python -m sendmail
- Follow the auth flow.
Based on Gmail dev docs tutorial:
See also tutorial which uses a less secure approach and requires you to allow less secure apps.
See other sample scripts for Google suite.