An open source function to send emails using Gmail and generate OAUTH2 Tokens in Python.
Requirements
- Gmail & Google Developers/Gcloud Account
- Enable Gmail API and grant Send Email scope in your Google Developers/Gcloud Account
- Python 3
- Pip
Install
- Create a virtual environment
python -m venv venv
- Activate the virtual environment
./venv/scripts/activate
- Install requirements
pip install -r requirements.txt
- Replace EMAIL_FROM with your gmail (or other provider's) email address.
EMAIL_FROM = "youremail@gmail.com"
- Replace the following variables using credentials from your Google Developers/Gcloud Account
REDIRECT_URI = "--------"
CLIENT_ID = "-----------.apps.googleusercontent.com"
CLIENT_SECRET = "---------------"
Usage
- Run the app
python app.py
- Go through each option starting from #1
Select an option
1. Generate Authorization Code
2. Generate Tokens
3. Send Email
- For Option #1 You will go through the following steps on your browser when it generates a URL
- Replace the AUTHORIZATION_CODE variable from 'code' in the redirected url
AUTHORIZATION_CODE = ""
- Run the app again and select the remaining 2 options
python app.py
- Check your email for the successful result!