My First Apps Script: Damn these promo emails
Every so often, I will change something on my work laptop which requires connection to emails. We are a Gmail shop, so it connects and tells me I have 3200+ unread emails, which scares the living daylights out of me. This is because I use Gmail's little categorisation system - I have no emails in "primary", and frankly I don't look in Social, Promotions or Updates unless I really need to: hence the accumulation.
When this happens, it prompts me for the next week to feel mad about the state of my inbox, varying between annoyed externally that I receive so much promotional stuff (there is not a service on EARTH that requires marketing emails EVERY DAY) and annoyed internally that I haven't dealt with it. Just before Christmas 2024, I decided to take a few hours to see what I could do about the latter, and decided to see if there could be a sophisticated solution to this. Enter, this tiny little apps script.
Google Apps Scripts are basically JavaScript, which is a language I do not find particularly intuitive to write and do things in, but this was pretty straight forward to get going. Once the right search string has been identified (which you can test by searching your own mailbox), it's then a case of setting it up in the Apps Script console and scheduling it.
I decided to go for a 30 day retention period and run it on a weekly basis, which gives me plenty of time to catch an email I might actually want to read. This is pretty rare in the items Gmail classifies as "Promotions": "Updates" might be a bit of a tougher nut to crack, with more parameters.
Nonetheless, I'm happy that I got it done. My Gmail notification number isn't perfect, but is definitely a lot less of a shock.