error
code
Python
verified
Free Download
devices
Cross-platform
code Code Preview
Python#!/usr/bin/env python3
"""
Email Bounce Analyzer
Parse and categorize email bounce messages
"""
import re
from enum import Enum
class BounceType(Enum):
HARD = 'hard_bounce'
SOFT = 'soft_bounce'
BLOCKED = 'blocked'
UNKNOWN = 'unknown'
BOUNCE_PATTERNS = {
BounceType.HARD: [
r'user unknown',
r'mailbox.*not.*found',
r'does.*not.*exist',
r'invalid.*recipient',
r'no such user',
r'address rejected',
r'recipient rejected'
],
BounceType.SOFT: [
r'mailbox.*full',
r'over.*quota',
r'temporary.*failure',
r'try.*later',
r'service.*unavailable',
r'connection.*timeout'
],
BounceType.BLOCKED: [
r'spam',
r'blacklist',
r'blocked',
r'rejected.*policy',
r'denied',
r'banned'
]
}
def analyze_bounce(email_body):
"""Analyze bounce message and return type"""
body_lower = email_body.lower()
for bounce_type, patterns in BOUNCE_PATTERNS.items():
for pattern in patterns:
if re.search(pattern, body_lower):
return bounce_type
return BounceType.UNKNOWN
def analyze_batch(bounce_messages):
"""Analyze multiple bounce messages"""
results = {t: [] for t in BounceType}
for msg in bounce_messages:
bounce_type = analyze_bounce(msg['body'])
results[bounce_type].append(msg['email'])
return results
if __name__ == '__main__':
sample = "Delivery failed: User unknown"
print(f"Type: {analyze_bounce(sample).value}")
info About This Tool
The Email Bounce Analyzer parses bounce messages and categorizes them by type. Understanding bounce types helps you clean your email list and improve deliverability.
Bounce Categories
- Hard Bounce - Permanent failures (invalid addresses, non-existent domains)
- Soft Bounce - Temporary issues (mailbox full, server down)
- Blocked - Rejected by spam filters or blacklists
- Unknown - Unrecognized bounce patterns
Key Features
- Pattern Matching - 20+ bounce patterns recognized
- Batch Processing - Analyze multiple bounces at once
- Email Extraction - Extracts bounced addresses from messages
- Report Generation - Summary stats by bounce type
Requirements
- Python 3.7+
- No external dependencies
Important: Always remove hard bounces immediately. Continued sending damages sender reputation.
download Download Script
Need Full Automation?
Try Postigo for automated email campaigns with AI personalization
rocket_launch Start Free Trial