Automatically deletes old emails that match the specified label.
- Create a new Google Apps Script at https://script.google.com
- Overwrite the placeholder with the javascript below
- Update the following constants:
LABEL_TO_DELETE
: the label that should be have old messages deletedDELETE_AFTER_DAYS
: the age of messsages after which they will be moved to trash
- Save the script, then run:
Initialize
Install
If you ever want to remove the script, run Uninstall
to remove any left over triggers.
- Added support for multiple labels
- Added configurable
TRIGGER_NAME
- Increased default page size
- Decreased default delay between receipt and delete
- Removed use of deprecated
Session.getTimeZone()
- Improved efficiency for long threads by checking
thread.getLastMessageDate()
H/T: Arun's post How to Auto Delete Old Emails In Any Gmail Label
Thanking a lot for this amazing code. I am using it to get rid of hundreds of emails on a regular basis AUTOMATICALLY! This script has saved a lot of effort and increased productivity. I wrote a post about it here: https://www.linkedin.com/posts/theparin_gmail-delete-old-emails-automatically-activity-6782625622943498241-Et86
Initially, 4 months ago, I had a problem deleting emails from multiple labels when I was putting the names of multiple labels in the script and it didn't delete any of them at all. But, Just now, at this very moment, I found a 10-year old answer on https://webapps.stackexchange.com/questions/10581/filtering-based-on-multiple-labels-in-gmail , saying that we need to add '-' sign if the label names have spaces in them. And now, it is working properly as it should. just writing it here because if anyone else faces the same problem, it will help them with that tiny issue.
Thanks again, @jamesramsay !