Gmail - Automatically mark archived mail as read


2 min read

Gmail - Automatically mark archived mail as read

I'm lazy, no getting around that but over the last year or so I've been able to maintain zero emails in my Gmail inbox. One of the ways I lazily do this is by archiving the vast majority of mail that requires no action but I may need to refer back to in the future. The rest head straight to the trash bin.

Archiving emails both in the mobile apps and web browser is straightforward and can be done in one click without even opening the email! That's great but when I look in the All Mail folder I see a bunch of unread emails, there must be a way to automatically mark archived mail as read. The short answer is yes there is!

You can create a Google Apps Script that runs on a trigger (e.g. hourly) and will mark all those pesky archived emails as read.

Setup a Google Apps Script

Go to Google Apps Script

Press New project

In the code editor, enter the following:

function markArchivedAsRead() { 
    var threads ='label:unread -label:inbox', 0, 100); 

Note - what this does is use the Gmail API to get the first 100 emails that are marked as unread (label:unread) and that are NOT in your inbox (-label:inbox)

Press the Run button (play symbol)

You will be prompted to save, and give it a name like markArchivedAsRead.

Press Run again and click Review Permissions

You will be prompted to select an account to authorise against, select your account.

google app script verify

As this app isn't verified by Google you will get the above warning, click on Advanced (bottom left) and press the Go to ... (unsafe).

Review the permissions and press Allow

The function will then run for the first time but will only mark the first 100 emails as read. For it to run regularly, you need to set up a trigger.

Go to Edit > Current project's triggers

Press create a new trigger

google app script trigger

Fill out the trigger like the image above, you can change the hour interval to whatever works for you. I've found that "every 4 hours" works great for me but maybe you're so popular that you need to run it more often.

Press Save to commit your changes and apply the trigger.

You can now leave it alone and enjoy email bliss!

Note - if you have a bunch of old unread mail in your All Mail folder you can run the script manually a couple of times for it to process the backlog.