A powerful Python-based tool to detect fully blocked email batches by analyzing Gmail bounce (DSN) messages.
BatchBounce Analyzer is designed for developers, marketers, and automation systems that rely on bulk email sending.
It connects to multiple Gmail accounts and analyzes recent bounce (DSN) emails to identify:
- Fully blocked email batches
- Affected recipients
- Problematic sending accounts
This helps you quickly detect deliverability issues and take action before damaging your sender reputation.
- Connects to Gmail using IMAP
- Scans the last 50 bounce (DSN) emails from:
- Inbox
- Spam (optional)
- Extracts:
- Failed recipients
- Original message IDs (to group batches)
- Groups failures into batches
- Detects fully blocked batches (≥ 10 recipients)
- Generates a CSV report
- Prints a detailed summary
- 📬 Multi Gmail account support
- 🔍 Smart DSN/bounce detection
- 📊 Full batch block identification
- 🧠 Advanced recipient extraction (headers + body)
- ⚡ Fast processing (limited scan scope)
- 🔁 Retry mechanism for network errors
- 📁 CSV export for analysis
- 👁 Preserves unread/read email status
- 🗂 Optional Spam folder scanning
This project uses only built-in Python libraries:
- imaplib
- re
- json
- csv
- os
- time
- socket
- html
No external dependencies required.
Create a file named credentials.json:
[
{
"email": "your_email@gmail.com",
"password": "your_app_password"
}
]Use Gmail App Password, not your actual password Enable 2FA before generating app password
git clone https://github.com/yourusername/BatchBounce-Analyzer.git
cd BatchBounce-AnalyzerEnsure Python 3.8 or higher is installed:
python --version
- All required libraries are built-in.
Run the script:
python BatchBounce-Analyzer.py
File generated:
full_batch_blocks_report.csv
- Number of blocked batches per account
- List of affected Gmail accounts
- Unique failed recipients
- Automatic bounce messages sent by mail servers when delivery fails.
- A batch is considered fully blocked when:
10 or more recipients fail (default setting)
You can modify these values inside the script:
BATCH_SIZE = 10
LAST_N_MESSAGES = 50
SCAN_SPAM = True
MAX_ACCOUNT_RETRIES = 3
RETRY_DELAY_SECONDS = 5
- Email marketing systems
- Cold email automation tools
- Lead generation pipelines
- Deliverability monitoring systems
- Gmail account health tracking
- Works only with Gmail (IMAP)
- Requires App Password authentication
- Not real-time (batch analysis only)
- Accuracy depends on DSN formats
- Never share your credentials.json file
- Do not upload credentials to GitHub
- Always use App Passwords
- Consider encrypting credentials for production
Malki Aman
For business inquiries or custom solutions:
- GitHub: malkiaman-dev
- Email: your-email
If you find this project useful, give it a star ⭐
This tool is intended for ethical and legal use only. Users are responsible for complying with email laws and service provider policies.