Email Tips: Clean Up Your Inbox With A Google Apps Script

clean up gmailEmail is undoubtedly important—and at the same time, it can be a huge time drain depending on how much email you receive a day. And if your email inbox is anything like mine, well, it’s a jungle. Ready to tidy things up a bit? We stumbled on a Google Apps script that can help you better manage your Gmail inbox—no apps or extensions required.

We live our lives on a schedule (or try to, anyway)—so why not apply the same philosophy to your inbox? The Google Apps Script lets you automatically archive or delete old emails that are clogging up your inbox based on a schedule you create. The result? Time-based events that will move, mark or label messages—and you don’t even have to open your mail client!

I can hear your excitement. You’re ready to set it up, aren’t you? Let’s dive in with a hypothetical example. Say you want to get rid of deals, promotional emails or notifications that are two days old. To accomplish this, you’ll need to follow two steps:

1)    Create a “delete me” Gmail filter and populate the search options to catch your semi-spam as it arrives.

2)    Create a script that will delete all messages from the “delete me” label older than two days.

Once your filter has been created, go to https://script.google.com and create a blank project. You’ll enter the following code, as written on John Day’s blog–head there to copy and paste the script.

google apps clean up script

Notice that, in the second line, you have the option to change the number of delay variables to specify how many days should pass before that particular matched message will be deleted from your inbox.

When you’ve filled in the variables, save the script, name your project and click Run. After that, Google will ask you to authorize the script to access your Gmail account. Your final step is the schedule the interval at which you want the script to run. Simply go to the Resources menu and select your desired interval.

google apps script

Now that you’ve cleaned up older emails, what about the rest of your inbox? Don’t worry—there’s a script for that! You can easily archive older emails from your inbox using the Google Script here:

https://script.google.com/d/1FqkoGz0qhBxBfu2dbJMGL8yo-larautrN7ASJLHrGTxqkQtQNPEDX7CH/edit?usp=sharing

Simply copy and paste the script into https://script.google.com, specify your intervals and you’re set!

A quick note? If you want to clean up thousands of email messages, know that it will take time for the script to fully work. If you’d rather tackle your inbox in smaller batches, follow John’s steps to process email threads in groups of 100.

What do you think? Ready to give Google Apps Script a try? Be sure to let us know how it works. And if you have any other email management tips or tools, don’t be shy—give us the scoop!

Image: Mike Willis via Compfight cc

  • Ana Lucia Novak

    Hi there Shelley, great post on this toll, question: I set up filters for specific incoming email that automatically goes to trash, what is the difference between using filters vs. this tool?
    Thanks again !
    Ana Lucia Novak

  • http://twitter.com/mistygirlph Misty Belardo 

    Hi Ana, I don’t think there is much difference, except that it allows you to manage your inbox by not just deleting but also help you archive emails that you don’t want to throw away on a specified time that you set. Plus the script works only on Gmail. I hope my answer helped.

  • http://www.incion.com/ Website Designers in Orange Co

    Very nice email tips. Thanks for sharing.

  • http://twitter.com/mistygirlph Misty Belardo 

    Glad it was helpful :)

  • http://www.vongehrconsulting.com/ Erroin Martin

    Misty, great article and very helpful!

  • http://twitter.com/mistygirlph Misty Belardo 

    So glad it was helpful for you Erroin :)

  • http://www.online-phd-uk.co.uk/ OnlinePhDUK

    excellent article, brilliant tips…thanks for sharing!!!

  • Quinn

    Fails now with TypeError: Cannot call method “getThreads” of null. (line 8, file “Code”)

  • ShellyKramer

    Thanks for letting us know. We’ll check it out.

You can also find me on Google+ Real Time Web Analytics