Automatically Clean Up Gmail On A Schedule With This Script


Maintaining inbox zero and dealing with old emails takes work (for some, too much work!). This Google Apps script lightens the load a bit by automatically archiving or deleting old emails that are cluttering your inbox, based on a schedule you set.

Photo by Storozhenko (Shutterstock)

Whipped up by John Day, these time-based Gmail filters will move old read emails to the trash or auto-archive them.

So, for example, you could automatically get rid of expired daily deals emails or other promotional emails that are more than two days old. First, create a Gmail filter that automatically applies the label “delete me” to that semi-spam when it comes in.

Then the Google Apps script, which you’ll need to authorise for your Gmail account, takes care of deleting emails with that label that are older than two days. You can adjust the number of days before messages are moved to the trash in the script (see the delayDays variable and change the “2” to another number) and under the Resources > Current project’s triggers… option, set the script to check your inbox every half hour or other interval.

For those old, read emails you want to keep but move out of your inbox, there’s another function that archives them. (In the script you can also adjust the older_than search to something other than “2d” and add or exclude other labels.)

For more details, see John’s post, where he offers the code for you to paste into a new Google Apps Script. I’ve shared this Google Apps script with the two functions pasted in, so you can just make a copy of it to your account and run it per John’s instructions.

Create time-based Gmail filters with Google Apps Script [Johneday via adayzdone]


The Cheapest NBN 50 Plans

Here are the cheapest plans available for Australia’s most popular NBN speed tier.

At Lifehacker, we independently select and write about stuff we love and think you'll like too. We have affiliate and advertising partnerships, which means we may collect a share of sales or other compensation from the links on this page. BTW – prices are accurate and items in stock at the time of posting.

Comments


Leave a Reply