Google Apps Script that automatically removes/archives old emails based on sender.
(Easier for one-time deployment)
- Create a new Google Sheets workbook
- Make sure that you have 2 sheets in the workbook. One for removals, and one for archiving
- Add your rules to the workbook. The first column contains the email addresses; the second column contains the number of days before which the email should be deleted. Example here
- Head to the example project page
- On the left side, click Overview
- On the top-right side, click the copy icon to Make a copy
- Put the urls and sheet names into the top of
config.gs - Edit
config.gsto your liking - Navigate to
gmailAutoClean.gs, and clickRun - Setup Triggers (on the left) if you want to
(Easier for TypeScript source modification and future updates)
- Clone this project
- Run
npm installto install all the dependencies listed inpackage.json@google/clasp: For pushing code to Google Apps Script platform@types/google-apps-script: For TypeScript type checking
- Start a new project on Google Apps Script
- On the left side, click Project Settings
- Copy the Script ID, and replace the
scriptIdin.clasp.json - Create a new Google Sheets workbook
- Make sure that you have 2 sheets in the workbook. One for removals, and one for archiving
- Add your rules to the workbook. The first column contains the email addresses; the second column contains the number of days before which the email should be deleted. Example here
- Put the urls and sheet names into the top of
clasp-root/config.ts - Edit
clasp-root/config.tsto your liking - Locate the
claspbinary installed vianpm, which is usually located in./node_modules/.bin/ - Run
./node_modules/.bin/clasp loginwith appropriate path. Log into Google - Run
./node_modules/.bin/clasp push, or./node_modules/.bin/clasp push --watchif you intend to edit the code and have it update in real time - Go back to the project webpage and refresh
- Navigate to
gmailAutoClean.gs, and clickRun - Setup Triggers (on the left) if you want to
- Archived: search for
label:autoarchived - Removed: search for
label:autoremoved in:trash
- You'll have to grant the script necessary permissions to edit your emails.
- This script does not check or modify threads marked as "important" or emails that are starred.