Python utility that validates email addresses by resolving MX records and performing a minimal SMTP handshake (RCPT check). It can validate individual addresses, scan a file, or generate a "scrubbed" output file containing only addresses that appear deliverable.
- MX lookup using
dnspython - IPv4 resolution with fallback when name resolution fails
- Minimal SMTP handshake on port 25 for deliverability hints
- Concurrent validation for large lists (ThreadPoolExecutor)
- Scrub mode writes only valid emails to a new file
- Requirements: Python 3.8+.
- Install deps:
pip install -r requirements.txt. - Run:
python3 valid.py.
Run the interactive menu:
python3 valid.py
Menu options:
- Validate a single email
- Validate emails from a file (
.txtor.csv) - Scrub a file (produce a file with only valid addresses)
.txt: one email per line.csv: uses the first column of each row
- Invalid addresses are printed with reasons and appended to
error_log.txt. - Scrubbed results are saved next to the source:
name_scrub.txtorname_scrub.csv.
-
Validate single address:
- Choose option
1and entersomeone@example.com. - The tool prints ✅/❌ with the SMTP response code/message.
- Choose option
-
Validate from file:
- Place
emails.txtwith one address per line in this folder. - Choose option
2, pick the file from the list.
- Place
-
Scrub file:
- Place
emails.csv(address in first column) here. - Choose option
3; the scrubbed list is saved asemails_scrub.csv.
- Place
For each address:
- Split into
local@domain. - Lookup the domain's MX record.
- Resolve the MX host to IPv4 and connect on port 25.
- Issue
HELO,MAIL FROM, andRCPT TOfor the target. - Interpret the SMTP code:
250implies likely deliverable; other codes are treated as invalid.
Notes & caveats:
- Providers can greylist/tarpit/accept‑all; expect false positives/negatives.
- Port 25 may be blocked by your ISP/cloud; connectivity failures are inconclusive.
- Some servers only validate after DATA; RCPT 250 is not a guarantee.
- Legal/ethical: Validate lists you own the right to test. Respect anti‑abuse laws and provider terms.
- Warm‑up: For large lists, test in smaller batches to avoid rate limits.
- Backoff: Insert delays if you see repeated timeouts or 4xx deferrals.
- Retries: The tool retries transient network issues; consider re‑running on failures.
- Timeout hygiene: Default timeouts are conservative; adjust only if you understand trade‑offs.
- Data handling: Never store full SMTP transcripts for real user data unless necessary.
- Port 25 blocked: Try a network where SMTP egress is allowed.
- Name resolution issues: Ensure DNS works and outbound UDP/53 is permitted.
- Slow validations: Reduce
max_workersinvalidate_emails_concurrentlyor limit input size. - IPv6 pitfalls: The script uses IPv4 resolution explicitly to avoid IPv6 routing problems.
- No credentials required; uses a fake
MAIL FROMfor probing. - Do not run from sensitive networks without approvals; outbound SMTP can be monitored/blocked.
- Review
error_log.txtcontents before sharing.
- Main entry:
valid.py - Deps:
requirements.txt - Style: keep changes minimal and focused; prefer readability over micro‑optimizations.
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
python3 valid.py
- Tag a release after notable changes:
git tag -a vX.Y.Z -m "..." && git push --tags. - Update this README with behavior changes.
This project is licensed under the MIT License. See LICENSE for details.
