Gagne Marketing

I Deleted 38,621 Emails in About 90 Minutes

I Deleted 38,621 Emails in About 90 Minutes

I Deleted 38,621 Emails in About 90 Minutes

Started the script around 10pm. An hour and a half later, it was done.

38,621 emails moved to Trash in a single session. No clicking. No filters. No paying for some app that may or may not work.

Just a free Python script, the Gmail API, and about 30 minutes of setup.

Why Gmail’s Built-In Tools Don’t Cut It

Gmail lets you select all emails on a page and delete them. The problem is it only grabs 50 or 100 at a time depending on your settings.

If you have 40,000 emails, you’re clicking through that hundreds of times. Nobody does that. So the inbox just sits there, buried.

The script I use goes around that limit entirely. It connects directly to Gmail’s API and moves emails in large batches. No browser, no clicking.

What the Script Actually Does

It connects to your Gmail account through Google’s official API. You give it a keyword to protect, and it moves everything else to Trash.

It never auto-empties. You do that part manually when you’re ready. That’s intentional.

How the keyword protection works

You pick one word or phrase that matters. The script checks every email’s sender, subject, and body before touching it.

If your keyword shows up anywhere in the email, the script skips it completely. Everything else goes to Trash.

One client I helped only cared about emails from their attorney. We set the keyword to the attorney’s last name. Every one of those emails was untouched. Everything else got cleared.

It Runs a Test First

Before anything gets moved, the script runs in Test Mode. It shows you exactly what would be deleted without actually doing anything.

You review the list, confirm it looks right, then flip the switch. The live run only starts when you say so.

That matters. A script touching 38,000 emails should have a preview step.

What It Costs

Nothing, actually.

  • Google Cloud account: Free
  • Gmail API access: Free (well within Google’s quota)
  • Python: Free
  • No subscriptions, no third-party apps, no recurring fees

The only real cost

Setup time. There are a few steps to get the Gmail API connected and the script configured for your account. It’s not complicated, but it’s not one-click either.

That’s where I come in if you want help with it.

What You Need to Run It

  • A Google account (to create the free Cloud project)
  • Python installed on your computer (Mac usually has it already; Windows needs a quick install from python.org)
  • A terminal or VS Code
  • About 30 minutes for the initial setup

Windows note

If you’re on Windows, download Python from python.org. During the install, check the box that says “Add Python to PATH.” That one step saves a lot of headaches later.

A Few Things to Know

The script only touches your Inbox. Sent mail, Drafts, and other folders are never affected.

Nothing is permanently deleted by the script. It moves emails to Trash and stops there. You empty the Trash when you decide you’re ready.

This is practical automation. It does one thing, it does it well, and it doesn’t go beyond what you’ve told it to do.

What This Has to Do With AI Consulting

This is a good example of what I actually mean when I talk about AI and automation for small businesses.

It’s not about flashy tools or complicated setups. It’s about finding the right solution for a specific problem, understanding how it works, and making sure it doesn’t do anything you didn’t ask it to.

A lot of business owners I work with in Bradenton and Lakewood Ranch have the same inbox problem. It’s a small thing, but small things pile up. And solving them the right way builds confidence in the bigger stuff.

If you want help setting this up or want to talk through what other simple automations could save you time, reach out and we can figure it out together.

No pressure. It’s a free script. I’m just the person who can help you actually use it.