These scripts based on the quickstart code at https://developers.google.com/gmail/api/quickstart/python#step_1_install_the_google_client_library
- Have
python
andpipenv
installed - In the repo root run
pipenv install
which will install the dependancies for the APIs. - DON'T just run the scripts. You need to modify them first
- Get a
credentials.js
file. create your own https://developers.google.com/workspace/guides/create-credentials- Gmail API.
- Select the
https://mail.google.com/
scope when needed. - When you have downloaded the credentials file update the path to point to it in both scripts.
- run
pipenv shell
to put you in the virtual environment which contains all the right packages. - Identify the Label ID for your particular label.
- Run the Script
python quickstart.py
- It will open a browser window and ask you to allow the application to access your account
- It will then print out the labels and IDs for your emails.
- Authorization will only happen the first time, or after token expiry.
- Run the Script
- Modify the
delete-emails.py
script to use your label id - Run the script
python delete-emails.py
- Line 91 is commented out this is the line that ACTUALLY does the deletion uncomment when you are ready.