Simple Inbox Management + Decluttering for Solopreneurs
How to Automate Deleting Unread Emails in Gmail (Without Losing the Important Ones!)
Spoiler alert: this blog post has 0% to do with copywriting! But when I shared on Instagram that I’d figured out an automation for deleting old emails I don’t want, people went absolutely FERAL for it in my DMs.
So here I am, taking one for the team and showing you how to do the same!
“Why not just unsubscribe from newsletters that clutter your inbox?” people who are not like me might say. Well…
Because I’m a copywriter!
And, ya know, a small business owner who generally likes reading what other people have to share. So I don’t actually want to fully unsubscribe, but given that I only read a small smattering of what ends up in my inbox, unread stuff piles up FAST.
It’s overwhelming (not to mention just a waste of time) to keep up with manually culling it all. And at the same time, I often star or mark unread emails as important to come back to later, which means that mass-deleting everything unread also screws me up.
I’ve tried inbox filters, I’ve tried making myself delete stuff on CEO Mondays, I’m sure plenty of ops people out there would have me set up some sort of SOP for this situation, but I do not want complicated! I do not want “systems”! I want simple and easy and “never have to think about this again”!
Which led me to something I’ve never heard of before… the Google Apps Script.
And THIS is the magic that lets me automatically delete unread emails older than ten days, all while keeping my starred and important ones safe. And it’s not that hard to set up!
Setting Up Your Google Apps Script
Betcha you didn’t know this was a whole section in your Google Drive you’ve never visited, eh? Me neither. WELCOME.
Step 1: Open Google Drive
Step 2: Create a New Script
Create a New Project:
Click on the “New” button in the upper left corner.
Hover over “More” and then select “Google Apps Script.” (Yeah, I didn’t know this section existed either.) This opens a new tab with a blank script editor where all the magic will happen.
Step 3: Name Your Project
Name Your Script:
In the top left corner, you’ll see “Untitled project.” Click on that and give your project a real name—something like “Delete old unread emails.”
Step 4: Paste in the Code
First, Clear Out the Default Code (the function myFunction stuff).
Then, Copy and Paste this Code:
function deleteOldUnreadEmails() {
// Search for unread emails that are older than 10 days and are NOT starred or marked as important
var threads = GmailApp.search('is:unread older_than:10d -is:starred -is:important');
for (var i = 0; i < threads.length; i++) {
threads[i].moveToTrash();
}
}
Make sure that you include both of those straggler brackets at the end! And paste it in as plaintext (Command + Shift + V on a Mac) so that there aren’t empty lines between each line of code.
It should look like this:
This code is doing what I personally want it to do: moving unread emails that are older than 10 days and are NOT starred or marked as important to the trash.
(You could definitely update the time interval to your liking—I chose 10 days to cover my ass if I was out for a week of vacation.)
Step 5: Save Your Script
Now click on the disk icon (💾) in the top left corner to save your script. (Nothing’s gonna happen yet, don’t worry!)
And congratulations, you are now a Woman in STEM!!! Look at you feeling like a hacker!!
Now you just have to set up the trigger and you’ll be done.
Setting Up Your Trigger + Manual Deployment
Now the script exists, but you need to set up a trigger to finish up and make sure it’ll actually run on its own. (You’ll also manually deploy it the first time to make sure it’s working.)
Step 1: Access Triggers
Open Your Script:
Make sure you’re still in the Google Apps Script editor with your project open.
Open the Triggers Menu:
In the far left sidebar, click on the clock icon (🕒) to open the Triggers menu.
Step 2: Create a New Trigger
Add a New Trigger:
Click on the “Add Trigger” button in the bottom right corner, and a new window will open up.
Step 3: Configure Your Trigger Settings
Choose Which Function to Run:
In the dropdown menu labeled “Choose which function to run,” select deleteOldUnreadEmails (or whatever you called it).
Choose Which Deployment Should Run:
Keep this as “Head.” (Just a fancy way of saying you want to run the latest version of your script.)
Select Event Source:
Choose “Time-driven.” This tells Google to run your script based on a time schedule rather than in response to an event.
Select Type of Time-Based Trigger:
Choose “Day timer.” This will allow you to run the script once a day.
Select Time of Day:
You’ll now see options for when to run the script. I just set it to run overnight in the Midnight to 1AM window.
Failure Notification Settings:
For notifications, you can select “Notify me daily” or “Notify me immediately” based on your pref.
Save Your Trigger:
Once you’ve filled everything out, click “Save.” Your trigger is now set up to run automatically every day!
Deal with the Popup:
Now, a slightly scary-looking authorization pop-up window is going to prompt you to give this thing the green light. Did I love clicking this permission to edit my inbox? No, but that’s what I want it to do, soooo, it is what it is.
*If you have a popup blocker installed (which is likely if you’re using Google Chrome), what you may get instead is no popup and an icon of a screen with an X through it will appear in your browser toolbar. Click on that icon, enable the popup, and proceed with giving permission.
Step 4: Test it, babyyyyy!
Deploy the Script Manually for the First Time:
In your script, you should see a “▷Run” button. Click it to trash those old emails!
Check Your Inbox:
This may take a minute or two, so don’t freak out if the emails don’t disappear right away. But after the script runs, if those old emails are in the trash, it’s working!
One more thing: don’t forget that you can rescue emails from the Trash!
Because this script is moving these emails into your Trash and not, say, immediately incinerating them Howler-style, if anything goes wrong you should be able to retrieve the deleted emails! Stuff stays in your Trash for 30 days before it’s permanently deleted, so if you accidentally miss something important, no need to panic.
And now, your inbox will magically clear itself out while keeping the stuff you DO need.
I know, I know… I just changed your freaking life.
Now, it’s a bummer for me that figuring out this hack has absolutely nothing to do with my business/what I actually offer, but hey, hot girls don’t gatekeep. 😂
So I genuinely hope this helps take some boring crap off of your plate and keeps your brain feeling a little calmer!
And, just saying, if you feel inclined to get two emails a month that you WON’T want to leave unread, you can invite me into your inbox right here. (No clickbait, FOMO, or those misleading subject lines that are still annoyingly popular.)
Every other Tuesday, I share copywriting tips, small biz reflections, and the much loved “Little Flame Reads & Recs” roundup, and I’d love to have you join in!
K, go set up your script!