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"
- Go to OAuth Consent
- Choose "External" β "CREATE"
- Fill in:
- App name:
Gmail Bulk Delete - User support email: [your email]
- Developer contact: [your email]
- App name:
- Click "SAVE AND CONTINUE"
- Click "ADD OR REMOVE SCOPES"
- In the filter box, paste:
https://mail.google.com/ - Check the box next to
https://mail.google.com/ - Click "UPDATE" β "SAVE AND CONTINUE"
- Click "ADD USERS" β Enter your Gmail address β "ADD"
- Click "SAVE AND CONTINUE" β "BACK TO DASHBOARD"
- Go to Credentials
- Click "+ CREATE CREDENTIALS" β "OAuth client ID"
- Application type: "Desktop app"
- Name:
Gmail Delete Desktop - Click "CREATE"
- Click "DOWNLOAD JSON" button (β¬οΈ 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!