How I make Google, pay to keep my Gmail Clean

Jude Osbert
5 min readJan 24, 2024

If you are one of those lucky persons blessed to see this little red bar everyday this article is for you.

Welcome to the club!

Google’s evil plan to make us pay for the service which were once “FREE” has come to its final act. And its time for the Goliath to meet its David.

Okay, lets get real. Its not that Google is evil in making us pay for using additional storage beyond the free tier. Its just that I am lazy to clean up my email, I am also too cheap to pay for my emails inbox.

Problem Statement

To create a system that can clean my email everyday with the ability to choose which emails to keep and which to delete!

Prerequisites:

  1. A gmail inbox!
  2. A Google drive with space to create a spreadsheet!

Procedure:

  1. We need to create a new Google sheet in the account we want to clean. Click here to create new google sheet.
  2. We will be using a concept called Appscript which is included for free with every Google Sheet. Click on Extensions>Appscript to open the window of Appscript.

3. You will be greeted with this blank screen to write your script.

डरो मत

4. Copy and paste the following code replacing the existing contents and click on the floppy disk icon to save the script.

In short this script searches your email inbox with query specified which says , “find email without the label keep-app-label. “ Since this label is new and might not be applied to old emails there will be a lot of them and all emails might be selected. To limit this I have also applied a filter on date so that only emails received after 1st Jan 2024 will be selected.

Make sure that the label already exists in your gmail account. If not this script will fail.

5. Create the label if it doesn’t exist

To create the label if its doesn’t exists open Gmail in a new tab and click on the plus button like below

6. Now that the label is ready and the script is ready, it is time for us to decide at what time should we run the script. For my purposes, I found that I will run this query everyday around 11pm to 12am so that I can look at the emails in the day and apply the label to the emails I want to keep and others would be deleted.

7. To trigger this script click on the alarm clock icon in the left hand side menu.

8. Once the page opens click on the Add trigger button

9. This opens a popup dialog. Make sure that the values match the ones I have selected. Refer the following screenshot for the values to set it to

10. Click on save once done. Clicking on save will ask you to login to authorise access. Continue to login and skip and warnings since you are the owner of the project and my code is not shady! 🙂

If you come across this warning

click on Advanced and then

Go to untitled project button and click Allow on the next screen.

If everything was successful you should see the trigger created like below

Result

You have now created an app script that will run every day towards the end of the day and remove emails which doesn’t have the label applied.

Conclusion

From the day this script was employed, it has done a good job of keeping my inbox clean especially emails that fall under social and promotions tab which I rarely open. I have also noticed that I have started to go through these tabs as well since I have to see if there are any emails that I need to keep like receipts for different services, important documents shared etc.

But what do we do about older emails that is already taking up space? I am working on a side project which will help you easily go through your emails and keep or remove them. Follow and stay tuned for it!

Please leave your comments or thoughts below!

--

--