Hey dev community! π
As developers, our inboxes often turn into a graveyard of job alerts (LinkedIn, Indeed, ZipRecruiter) and tech newsletters we subscribe to with the intention of "reading later" but never actually open. The result? Important emails get lost, and we get the dreaded "Account storage is almost full" notification.
Recently, I hit that wall. I had thousands of accumulated emails. While Gmail allows you to create filters for incoming mail, it doesn't have a native feature to say: "Delete this email automatically after 7 days".
So, I decided to solve it the way we solve everything: by writing some code.
π οΈ The Solution: Google Apps Script + JavaScript
Since the Google Workspace ecosystem runs on a JavaScript-based environment, I put together a custom script. Fun fact: a simple loop originally failed due to Google's strict 6-minute execution limit. To fix this, I optimized the code to process emails in batches of 100, preventing the server from timing out.
Here is the final production-ready script:
function cleanSpamTsunami() {
// 1. Loop to delete ALL Job Board emails in batches of 100
var continueJobSearch = true;
while (continueJobSearch) {
var jobThreads = GmailApp.search('computrabajo OR indeed OR linkedin OR OCC OR neuvoo OR talent.com OR jooble', 0, 100);
if (jobThreads.length > 0) {
Logger.log('Deleting a batch of ' + jobThreads.length + ' job alert emails...');
GmailApp.moveThreadsToTrash(jobThreads);
} else {
Logger.log('No more job alerts found!');
continueJobSearch = false; // Break the loop
}
}
// 2. Loop to delete old Newsletters (older than 7 days) in batches of 100
var continueNewsletters = true;
while (continueNewsletters) {
var newsletterThreads = GmailApp.search('unsubscribe OR "cancelar suscripciΓ³n" older_than:7d', 0, 100);
if (newsletterThreads.length > 0) {
Logger.log('Deleting a batch of ' + newsletterThreads.length + ' old newsletters...');
GmailApp.moveThreadsToTrash(newsletterThreads);
} else {
Logger.log('No more old newsletters found!');
continueNewsletters = false; // Break the loop
}
}
Logger.log('Deep clean completed successfully.');
}
βοΈ How to Set It Up in 3 Steps:
- Create the Script: Head over to script.google.com, create a new project, and paste the code.
- Authorize it: Click Run (the Play button βΆοΈ) to authorize the script to access your account. > π‘ Note: Google will show a security warning because it's an unverified app. Don't worryβit's literally your own code. Just click **Advanced* -> Go to project (unsafe).*
- Automate it (The Trigger): On the left menu, click on Triggers (the Clock icon β°), select Add Trigger, and set it to run on a Time-driven event with a Daily timer scheduled between Midnight to 1 AM.
And that's it! Your inbox will stay clean, your storage optimized, and you'll hit a real automated Inbox Zero every single day.
What do you think? How do you handle inbox clutter or automate your dev environment? Let me know in the comments! π
π₯ A Personal Note from the Author
Hey everyone, thank you so much for reading this far.
Writing code and automating solutions is my passion, but recently I had to undergo a major unexpected surgery that has me temporarily bedridden. As a Java developer and the main provider for my family, being unable to work during this recovery phase has been a tough financial and emotional challenge.
I rarely do this, but I have launched a GoFundMe campaign to help cover medical expenses and support my family while I get back on my feet and return to coding at 100%.
If you found this script helpful, or if it saved you some storage space today, please consider supporting or sharing my campaign. Every little bit counts and means the world to us right now. πβ€οΈ
π Support or share the campaign here: Help Adrian & His Family on GoFundMe












