Auto archive emails in Gmail after 2 days

fwed
fwed
Jan 8, 2017 · 4 min read

Maintaining your inbox clean can be hard, as previously explained. The method described below makes it easier and only uses a Gmail label to automatise the archiving process on certain types of emails (newsletters, notifications, emails digests, etc).

Please bear in mind it’s a method to keep your inbox cleaned over time onward, this is not a method to get rid of the 20K unread and useless emails piling up in your inbox that you accumulated for the last 10 years.

Create an ‘autoarchive’ label

  1. Go to your Gmail Settings
  2. Click the Label tab
  3. Hit the Create new label button
  4. Name it autoarchive

Use Gmail filters to apply the ‘autoarchive’ label

Let’s say you want each notification you receive from Facebook to be automatically archived after 2 days. Follow the next steps to create a Gmail filter which is going to apply the ‘autoarchive’ label to these Facebook notifications.

  1. Open any email from Facebook
  2. Click on More in the top bar
  3. Click on Filter messages like these
  4. Then hit the Create filter with this search
  5. On the next screen, tick the Apply the label box, and select the autoarchive label
  6. Before you finish, tick the box Also apply to matching conversations at the bottom of the form
  7. Hit the Create filter button

From now on, all the emails received from Facebook will be labelled with the ‘autoarchive’ label. You can repeat that process to any other recurrent emails you get (Spotify notifications, Quora digests, LinkedIn recruiters, WordPress comments, etc).

Use a Google Script to archive daily

Follow the next steps to create a Google Script of your own and use the piece of code shown below:

  1. Go on script.google.com
  2. Copy and paste this code from GitHub into your Google Script
  3. Click File > Save
  4. Name it gmailAutoarchive (it will be saved in the root folder of your Google Drive)
  5. Go in the Run menu, then select gmailAutoarchive
  6. Google Script will require access to your Gmail (see screenshot below). Click Review Permissions.

7. Another window will appear, click Allow

Make sure it worked

First, bear in mind the Google Script I made only applies to emails that are at least 2 days old (48 hours). Also, the script does not go further back than 400 emails.

Now, to make sure it worked, follow the next steps.

  1. Go into your autoarchive label/folder to see all the emails it contains
  2. Check that all the emails older than 2 days do not have the ‘inbox’ label (meaning it has been archived)
Screenshot taken on the 8th. No email older than 2 days has the ‘inbox’ label.

If you still see emails that are more than 2 days old and that are labelled ‘inbox’, it could mean there are too many emails (the script only goes back to the previous 400 emails).

Setup a daily trigger

Within your Google Script window:

  1. Click on Edit > Current project’s triggers
  2. Then add a new trigger with the following settings: Time-driven, Hour timer, Every 12 hours

This will check every 12 hours if there are new emails to archive. See screenshot below.

Trigger setup

Tweak and customise the script

Having the script shown below as a base, you could code several and useful tweaks in order to:

  • only archive the unread emails
  • archive all emails regardless of the autoarchive label
  • archive emails only if you starred them

Or anything else you feel like would help to keep your inbox clean!


I am keen on knowing if this solution is working for you, or how you adapted it to suit your needs. Questions? Comments? Leave a note here or email me at contact@fwed.fr

fwed

Written by

fwed

master of none

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade