Created
April 28, 2018 12:09
-
-
Save yolossn/f4f8340da073bf52f7e040d7476a280c to your computer and use it in GitHub Desktop.
Check if Email id exists
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
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