A Google Apps Script script to automatically delete unarchived mail after 7 days that hasn't been starred or marked as important
- Backup your emails using Google Takeout.
- Load this script into a new Google Apps Script project.
- Execute the setPurgeTrigger() function to set a trigger that will call the purge() function every day.
A detailed blog post with more information can be found at https://benbjurstrom.com/purge-email
Thanks to this gist by jamesramsay for getting me started in the right direction.
@vedanta28 I assume it should work as posted, but here's my modified version that only deletes messages with specific labels I don't want to retain:
Edited: updated the description of what my modified search does, and removed the commented-out original search line