-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEmail_Verification.py
More file actions
44 lines (41 loc) · 1.45 KB
/
Copy pathEmail_Verification.py
File metadata and controls
44 lines (41 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from dns import resolver
import smtplib
import socket
import re
def check_syntax(email):
regex=r'[a-z0-9]+[\._]?[a-z0-9]+[@]\w+[.]\w{2,3}$'
if(re.search(regex,email)):
print("Check 1 (Syntax) Passed")
else:
print("Check 1 FAILED! Bad Syntax,Invalid Email!")
exit()
def check_dns(email,domain):
try:
records = resolver.resolve(domain,'MX')
mxRecord =str(records[0].exchange)
print("Check 2 (DNS - ",mxRecord+") Passed")
return mxRecord
except:
print("Check 2 FAILED! The domain",domain,"does not exist,Invalid Email!")
exit()
def check_response(email,domain,mxRecord):
try:
host = socket.gethostname()
server = smtplib.SMTP()
server.set_debuglevel(0)
server.connect(mxRecord)
server.helo(host)
server.mail(email)
code,message=server.recpt(str(email))
if codef == 250:
print("Check 3(SMTP response) Passed")
print(email,"is a VALID email address!")
else:
print("Check 3 FAILED! The user",email.split("@")[0],"does not exist,Invalid Email!")
except socket.error as socketerror:
print("Check 3 HALTEd! The domain",domain,"either does not have an SMTP or have restricted access through external scripts")
email = input("Enter your Email id:")
domain = email.split("@")[-1]
check_syntax(email)
mxRecord = check_dns(email,domain)
check_response(email,domain,mxRecord)