Skip to content

Instantly share code, notes, and snippets.

@yolossn
Created April 28, 2018 12:09
Show Gist options
  • Save yolossn/f4f8340da073bf52f7e040d7476a280c to your computer and use it in GitHub Desktop.
Save yolossn/f4f8340da073bf52f7e040d7476a280c to your computer and use it in GitHub Desktop.
Check if Email id exists
import re
import smtplib
import dns.resolver
def Verifier(eid):
verify=eid
fromAddress="[email protected]"
regex=r"[^@]+@[^@]+\.[^@]+"
match=re.match(regex,verify)
if match==None:
print("Bad Syantax")
raise ValueError("Bad Syntax")
splitAddress=verify.split("@")
domain=str(splitAddress[1])
print("domain:",domain)
records=dns.resolver.query(domain,"MX")
mxRecord=records[0].exchange
mxRecord=str(mxRecord)
server=smtplib.SMTP()
server.set_debuglevel(4)
server.connect(mxRecord)
server.helo(server.local_hostname)
server.mail(fromAddress)
code,message=server.rcpt(str(verify))
server.quit()
if code==250:
return True
else:
return False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment