Auto-purge newsletters after a week using Google AppScript

If you use Gmail for keeping up with 10,000 newsletters, you need this.

I subscribe to a ton of newsletters and was getting FOMO due to not being able to keep up. I use a filter in Gmail to send all newsletters to a “Newsletter” label.

This script sends emails older than 1 week to another label “Old Newsletters” so that any given day I have a constant number of emails in my Newsletter label (+-10).

If you want to delete them permanently (though Trash stores them for 30 days) then the scripts in the Helpful Links section will be more useful.

The reason I don’t simply delete them is because a lot of newsletters don’t have an archive with all previous issues (substack ones have these) so having them archived within another label gives me some reassurance.

I mean it’s not that easy to overcome FOMO, collector’s fallacy 😅!

Steps to follow:

  1. Go to Google Scripts and click on “+ New Project”.
  2. Copy the below code snippet in gmail label modifier.js and paste it in your Google Script project and also remove the placeholder code function myFunction() {} present there.
  3. Modify the variables LABELS_TO_DELETE, ARCHIVE_LABEL, DELETE_AFTER_DAYS according to your needs. Read the comments in the code for more info on these variables.
  4. Save the script using the save icon in the toolbar.
  5. Select Initialize from the dropdown menu in the toolbar and run it.
  6. Then select Install from the menu and run it.
  7. That’s it done! You can see all the script executions here.
  8. If you want to stop this automated script anytime, then open this project and select Uninstall and run it.

This has been working great for me for the past 2 days. Let me know (twitter) if this was useful for you :)

Shashank
Shashank

Hey! I’m Shashank, a CS undergrad. I like to read, think, solve problems across multiple disciplines. Primarily exploring/interested in solving problems related to climate change, effective learning, ML & mixed reality.

Previous