Created
December 19, 2019 20:35
-
-
Save M4cs/bddd818292f97270ca0a343ab8ea2bdf to your computer and use it in GitHub Desktop.
Email Validator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# On Python3 run: `pip3 install dnspython` | |
import dns.resolver | |
import re | |
def verify_email(email): | |
regex = '^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$' | |
if re.search(regex,email): | |
pass | |
else: | |
return False | |
domain = email.split('@')[1] | |
records = [] | |
try: | |
for x in dns.resolver.query(domain, 'MX'): | |
records.append(x) | |
except dns.resolver.NoAnswer: | |
return False | |
if len(records) > 0: | |
return True | |
return False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment