Skip to content
Home » Blog » Science » Computer Science » Web Development » Messy Gmail Inbox? Automate It!

Messy Gmail Inbox? Automate It!

2 minute read
Google inbox automation

I don’t know about you, but I receive tons of emails each day in my Gmail inbox. Some are my fault; I had signed up for a newsletter on a whim because it was something I was actually interested in (like sales at Michael’s or DSW), and others might just be a result of third-party companies selling your data for profit and you end up on some list that’s kind of related to a thing you bought once on eBay three years ago.

Since I’m a developer and this was a pressure point for me with technology, there had to be a way for me to fix this problem with code! I managed to do so with a Google Script and I am sharing it with the world!

Get “Gmail Auto-Organize” script now

I used to be vigilant in sorting my email. I’d go through everything and delete promotions that were no longer in date, archive reports on accounts from weeks ago, and sort my client emails in the inbox into folders. But then it started taking longer and longer to sort my Gmail. There was just too much! So I started to unsubscribe or update my preferences to be less frequent, but I still had thousands of emails to delete or archive, so what to do?

First, I looked at the Spam and Trash folder since they already had this feature. I had hoped to find a checkbox or something in my settings to simply enable it. Unfortunately, this was not the case. Next, I searched Google. While I am a developer, part of my mantra includes not reinventing the wheel. Surely I’m not the first person to want this, so maybe someone already created something to help!

I came upon this Gmail Auto Purge tool by Digital Inspiration, written in Google Scripts. It is a very simple tool that simply takes a Gmail label and the number of days and then it just deletes emails based on those parameters. However, it didn’t encompass all of my needs. For starters, I need to also automatically archive emails in the Updates category because I don’t want to delete them forever (like digital receipts for tax purposes), and secondly, it only used the “label” parameter in the search and I needed to use “category”. Thankfully, Digital Inspiration posted their source code for the script, so it gave me a starting point. Here is the criteria I wanted to be able to change about their script:

  1. Ability to choose a “Do This” action, even if it’s just a boolean between deleting and archiving. Ideally, I’d like to have the same options as I do when creating a filter.
  2. Ability to use any search query, specifically “category:promotions”, “category:updates”, and “category:social”.
  3. Change how often it runs from once a day to every week or even once a month. As a developer, I feel like I need to consider processing power, and I don’t particularly care if I have an email in my Promotions category that is exactly 30 days and 5 hours old. It can wait until the script runs again every 3 days or so to delete that one.

So with that, I wrote my first Google Script to solve all my problems. Yay, technology!


This article was originally published on July 20, 2017, on the Flying Cork blog.

Nobody has commented on this yet, be the first!