Menu

Post image 1
Post image 2
1 / 2
0

Python Email Validator: Check 10,000 Emails in Under a Minute

DEV Community·Brad·18 days ago
#QdgN661u
Reading 0:00
15s threshold

Python Email Validator: Check 10,000 Emails in Under a Minute Stop sending emails to dead addresses. This Python script validates email lists in bulk. Install pip install dnspython Enter fullscreen mode Exit fullscreen mode The Script import re import dns.resolver from concurrent.futures import ThreadPoolExecutor def validate_format ( email ): pattern = r ' ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$ ' return bool ( re . match ( pattern , email )) def check_mx ( domain ): try : dns . resolver . resolve ( domain , ' MX ' ) return True except : return False def validate ( email ): if not validate_format ( email ): return False , ' bad_format ' domain = email . split ( ' @ ' )[ 1 ] if not check_mx ( domain ): return False , ' no_mx ' return True , ' valid ' def batch_validate ( emails , workers = 50 ): with ThreadPoolExecutor ( max_workers = workers ) as ex : return list ( ex .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More