Skip to content

Instantly share code, notes, and snippets.

@M4cs
Created December 19, 2019 20:35
Show Gist options
  • Save M4cs/bddd818292f97270ca0a343ab8ea2bdf to your computer and use it in GitHub Desktop.
Save M4cs/bddd818292f97270ca0a343ab8ea2bdf to your computer and use it in GitHub Desktop.
Email Validator
# 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