Auto-Purge Emails Script 📦 Setup rules and labels to clean up all emails older than 10, 30 or 90 days
- Sign in to your Google Account.
- To open the script editor, go to script.google.com. If this is the first time you've been to script.google.com, click
View Dashboard
. - At the top left, click
New project
. - Delete any code in the script editor and add the
Code.gs
file. - At the top, click
Save
. - At the top left, click
Untitled project
and enter a name for your script.
- Open Gmail.
- In the search box at the top, click the Down arrow.
- Enter your search criteria. If you want to check that your search worked correctly, see what emails show up by clicking Search.
- At the bottom of the search window, click
Create filter
. - Choose
Apply the label
: and choose/create a label with the name you setup in the script. example: .Deleted after 10 days
will automatically delete emails with this label 10 days after been receipt. .Deleted after 30 days
will be deleted 30 days after been receipt. .Deleted after 90 days
will be deleted 90 days after been receipt. - Click
Create filter
.
- Update the config in the editor to custom your labels and pruge schedule
- At the top of the editor, select
Initialize
and clickRun
. - In the first dialog box that appears, click
Review permissions
. In the second dialog box, review the permissions your script uses and clickAllow
. - At the top of the editor, select
Install
and clickRun
to install the script. - You can now exit this window and any email messages in Gmail folder will automatically get purged after 'n' days. The script will run by itself everyday at 01:00 hours.
Also, to stop the purging script anytime you can select Uninstall and click Run.