A Python tool to permanently delete thousands of Gmail emails by label in minutes. Free up your Gmail storage without paying for Google One!
- 🎯 Delete all emails in a specific Gmail label
- 💾 Permanent deletion - frees storage immediately (bypasses trash)
- 🚀 Fast - delete 10,000+ emails per minute
- 🔄 Auto-resume if interrupted
- ☕ Prevents Mac from sleeping during deletion
- 📊 Real-time progress tracking
- 🔒 100% local - your credentials never leave your computer
- macOS (tested on macOS 12+)
- Python 3.8 or higher
- A Gmail account
- 10 minutes for setup
# Install Homebrew if you don't have it
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# Install pyenv
brew install pyenv
# Add pyenv to zsh config
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zshrc
echo 'eval "$(pyenv init --path)"' >> ~/.zshrc
echo 'eval "$(pyenv init -)"' >> ~/.zshrc
# Reload shell configuration
source ~/.zshrc# Clone the repository
git clone https://github.com/chungnguyen-dev/gmail-bulk-delete.git
cd gmail-bulk-delete
# Install Python 3.12 (or your preferred version 3.8+)
pyenv install 3.12.6
# Set Python version for this project
pyenv local 3.12.6
# Verify correct Python version
python --version # Should show: Python 3.12.6
# Create virtual environment
python -m venv .venv
# Activate virtual environment
source .venv/bin/activate
# Install dependencies
pip install --upgrade pip
pip install --upgrade google-api-python-client google-auth-httplib2 google-auth-oauthlib- Go to Google Cloud Console
- Click "Select a project" → "NEW PROJECT"
- Project name:
Gmail Bulk Delete→ Click "CREATE" - Wait ~10 seconds for creation
- Make sure your project is selected (check top left)
- Go to API Library
- Search: "Gmail API"
- Click "Gmail API" → Click "ENABLE"
- In the Cloud Console sidebar go to:
APIs & Services → OAuth consent screen - If you are redirected to Google Auth Platform / Overview:
- Click Get Started to configure your OAuth setup.
- Under Branding / App Information:
- App name:
Gmail Bulk Delete - User support email: [your email]
- (Optional) Logo / home page
- Click Next.
- App name:
- Under Audience:
- Choose External
- Click Next.
- Contact information:
- Enter your email address where you want to receive notifications.
- Click Next.
- Finish / Create:
- Review the Google API Services User Data Policy and accept.
- Click Create.
- After creation you should now be in the OAuth configuration dashboard.
- In the OAuth screen dashboard, go to Data access → Add or remove scopes.
- In the filter box, paste:
https://mail.google.com/ - Check the box next to the Gmail scope.
- Click Update → Save.
If you selected External, you need to add test users before using the OAuth flow:
- Still in the OAuth screen menu, go to Audience → Test users.
- Click Add users.
- Enter your Gmail address.
- Save.
- Go to Credentials
- Click + CREATE CREDENTIALS → OAuth client ID.
- Application type: Desktop app.
- Name:
Gmail Delete Desktop. - Click CREATE.
- Click DOWNLOAD JSON (⬇️ icon).
- Save the file as
credentials.jsonin your project folder.
# Make sure you're in the project folder
cd gmail-bulk-delete
# Activate virtual environment
source .venv/bin/activate
# Run the tool
python gmail_delete.pyWhat happens:
- 🌐 Browser opens for Gmail authentication
- 🔑 Login with your Google account
⚠️ Click "Advanced" → "Go to Gmail Bulk Delete (unsafe)"- ✅ Click "Allow" to grant permissions
- ✅ Browser shows "Authentication complete!" - close the tab
- 📋 Terminal shows your Gmail labels
- 🎯 Select a label by entering its number
- 📊 Tool shows how many emails will be deleted
⚠️ TypeDELETEto confirm- 🗑️ Deletion begins with real-time progress!
cd gmail-bulk-delete
source .venv/bin/activate
python gmail_delete.pyNo browser authentication needed - your token is saved!
============================================================
🚀 GMAIL BULK DELETE BY LABEL
============================================================
🔐 Authenticating with Gmail...
✅ Authentication successful!
📋 Fetching your Gmail labels...
============================================================
📁 YOUR GMAIL LABELS
============================================================
1. Newsletters
2. Promotions
3. Social
4. Old Projects
5. Archive 2020
============================================================
Total: 5 labels
🎯 Enter label number to delete emails from (or 'q' to quit): 1
🔍 Searching for emails in label...
📧 Total found: 12,450 emails
============================================================
⚠️ CONFIRMATION REQUIRED
============================================================
Label: Newsletters
Emails to delete: 12,450
Type: PERMANENT deletion (bypass trash)
Storage freed: Immediate
============================================================
⚠️ THIS CANNOT BE UNDONE!
🔴 Type 'DELETE' to confirm (or 'cancel' to abort): DELETE
☕ Sleep prevention enabled (Mac will stay awake)
🗑️ DELETING 12,450 EMAILS
============================================================
⚠️ Permanent deletion - emails will NOT go to trash
============================================================
✅ Progress: 1,000/12,450 (8.0%)
Speed: 12,000 emails/min | ETA: 1.0 min
✅ Progress: 5,000/12,450 (40.2%)
Speed: 11,950 emails/min | ETA: 0.6 min
✅ Progress: 10,000/12,450 (80.3%)
Speed: 11,920 emails/min | ETA: 0.2 min
✅ Progress: 12,450/12,450 (100.0%)
Speed: 11,890 emails/min | ETA: 0.0 min
============================================================
📊 DELETION REPORT
============================================================
Label: Newsletters
Total found: 12,450 emails
Successfully deleted: 12,450 emails
Errors: 0
Duration: 1.0 minutes
Average speed: 11,890 emails/minute
Quota used: 650 units
Efficiency: 19.2 emails/unit
============================================================
✅ SUCCESS! Your Gmail storage has been freed.
Deleted emails are gone permanently (not in trash)
😴 Sleep prevention disabled
If the program stops (you close it, Mac sleeps, network issue):
python gmail_delete.pyYou'll see:
============================================================
📂 PREVIOUS DELETION FOUND
============================================================
Label: Newsletters
Deleted: 5,000 emails
Remaining: 7,450 emails
Last saved: 2025-02-16 14:30:45
============================================================
🔄 Resume from checkpoint? (yes/no): yes
Type yes and it continues exactly where it stopped!
The tool automatically manages Gmail API quotas and waits when needed.
Make sure you:
- Downloaded the OAuth credentials from Google Cloud Console
- Saved the file as exactly
credentials.json(notclient_secret_....json) - Placed it in the
gmail-bulk-deletefolder
You forgot to activate the virtual environment:
source .venv/bin/activateYour prompt should show (.venv) at the beginning.
Make sure pyenv is configured:
# Check Python version
python --version
# If it doesn't show 3.12.6, reinstall:
pyenv local 3.12.6You need to add the Gmail scope in OAuth consent screen:
- Go back to Step 3.3
- Make sure you added:
https://mail.google.com/ - Try running the script again
Manually copy the URL from the terminal and paste it into your browser.
- ✅
credentials.json- OAuth client ID (from Google) - ✅
token.pickle- Your authentication token - ✅
deletion_checkpoint.json- Progress data (temporary)
- ✅ Gmail API requests (to
gmail.googleapis.com) - ❌ Nothing else - no analytics, no tracking, no external servers
Q: Can I undo the deletion?
A: No. This is permanent deletion. That's why it asks you to type DELETE to confirm.
Q: Why permanent instead of moving to trash?
A: Emails in trash still use storage. Permanent deletion frees space immediately.
Q: Is it safe?
A: Yes. The code is open source - you can review it. It only uses official Gmail API.
Q: Will Google ban my account?
A: No. The tool respects all Gmail API quotas and limits.
Q: Can I delete from multiple labels?
A: Run the script multiple times and select different labels each time.
Q: What if I have 1 million emails?
A: It works! The tool saves progress every 1,000 emails.
Contributions welcome! Please feel free to submit a Pull Request.
MIT License - see LICENSE file
This tool permanently deletes emails. Use at your own risk. Always verify which label you're selecting before confirming deletion.
Made with ❤️ to help people reclaim their Gmail storage
Questions? Open an issue
Find it useful? Give it a ⭐ on GitHub!