Interact with your gmail account over the command line for quick batch operations. this currently only supports delete functionality by label or sender keyword.
takes roughly 10 minutes
-
Follow the python quickstart gmail API Docs to create a project, enable the gmail api, and download the credentials.
-
Rename the downloaded JSON file to credentials.json and copy it to the same directory as email_handler.py
-
Navigate to the directory you copied the script to.
-
Run the script and add the input variables: and . Label must be exact, but sender is a keyword search.
-
Ex:
$ python email_handler.py label='work' sender='[email protected]'
-
The script will open your browser to verify the OAUTH2 with the client and your gmail account.
-
Follow the command line prompst, the script will always ask before the final deletion of emails.
The gmail API does not allow instant and total deletion
This script just moves emails to the trash folder, which is cleared according to your settings
To allow instant and total deletion, you must submit a form to register your api with google, since this can be a security issue/dangerous if not used properly.
python quickstart gmail API Docs