Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a6b8a9e

Browse files
committed
Debugged Email Validation Script avinashkranjan#297
1 parent 27a4b12 commit a6b8a9e

File tree

2 files changed

+79
-25
lines changed

2 files changed

+79
-25
lines changed

‎Email-Validator/README.md‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,52 @@ A simple program which checks for Email Address Validity in three simple checks
1010

1111
- SMTP check, HELO, MAIL FROM and RCPT TO commands are implemented. In the RCPT, If the server sends back a 250, then that means we are good to send an email (the email address exists), otherwise the server will return a different status code (usually a 550), meaning the email address does not exist on that server.
1212

13+
---------------------------------------------------------------------
14+
## Requirements (Py modules used)
15+
- re (Regex)
16+
- dns
17+
- smtplib
18+
- socket
19+
20+
---------------------------------------------------------------------
21+
## TESTCASES
22+
```
23+
#INPUT
24+
mdsaaalikgmalia.com
25+
#OUTPUT
26+
Check 1 FAILED! Bad Syntax, Invalid Email!
27+
```
28+
```
29+
#INPUT
30+
mdsaaalik@gmalia.com
31+
#OUTPUT
32+
Check 1 (Syntax) Passed
33+
Check 2 FAILED! The domain gmalia.com does not exist, Invalid Email!
34+
```
35+
```
36+
#INPUT
37+
salik_invalid@gmail.com
38+
#OUTPUT
39+
Check 1 (Syntax) Passed
40+
Check 2 (DNS - gmail-smtp-in.l.google.com.) Passed
41+
Check 3 FAILED! The user salik_invalid does not exist, Invalid Email!
42+
```
43+
```
44+
#INPUT
45+
mdsaaalik@gmail.com
46+
#OUTPUT
47+
Check 1 (Syntax) Passed
48+
Check 2 (DNS - alt4.gmail-smtp-in.l.google.com.) Passed
49+
Check 3 (SMTP response) Passed
50+
mdsaaalik@gmail.com is a VALID email address!
51+
```
52+
```
53+
#INPUT
54+
mdsaaalik@yahoo.com
55+
#OUTPUT
56+
Check 1 (Syntax) Passed
57+
Check 2 (DNS - mta5.am0.yahoodns.net.) Passed
58+
Check 3 HALTED! The domain yahoo.com , either does not have an SMTP or have restricted access through external scripts
59+
```
60+
1361
#### By [Md Salik](https://github.com/saaalik)

‎Email-Validator/email_verification.py‎

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,45 +7,51 @@
77
def check_syntax(email):
88
regex = r'^[a-z0-9]+[\._]?[a-z0-9]+[@]\w+[.]\w{2,3}$'
99
if(re.search(regex,email)):
10-
pass
10+
print("Check 1 (Syntax) Passed")
1111
else:
12-
print("Invalid Email! Bad Syntax")
12+
print("Check 1 FAILED! Bad Syntax, Invalid Email!")
1313
exit()
1414

1515
#SECOND CHECK
16-
def check_dns(email):
17-
domain = email.split("@")[-1]
16+
def check_dns(email,domain):
1817
try:
1918
records = resolver.resolve(domain, 'MX')
2019
mxRecord = str(records[0].exchange)
20+
print("Check 2 (DNS -",mxRecord+") Passed")
2121
return mxRecord
2222
except:
23-
print("Invalid Email! The domain",domain,"does not exist")
23+
print("Check 2 FAILED! The domain",domain,"does not exist, Invalid Email!")
2424
exit()
2525

2626
#THIRD CHECK
27-
def check_response(email, mxRecord):
28-
# Get local server hostname
29-
host = socket.gethostname()
27+
def check_response(email, domain, mxRecord):
28+
try:
29+
# Get local server hostname
30+
host = socket.gethostname()
3031

31-
# SMTP lib setup (use debug level for full output)
32-
server = smtplib.SMTP()
33-
server.set_debuglevel(0)
32+
# SMTP lib setup (use debug level for full output)
33+
server = smtplib.SMTP()
34+
server.set_debuglevel(0)
3435

35-
# SMTP Conversation
36-
server.connect(mxRecord)
37-
server.helo(host)
38-
server.mail(email)
39-
code, message = server.rcpt(str(email))
40-
server.quit()
36+
# SMTP Conversation
37+
server.connect(mxRecord)
38+
server.helo(host)
39+
server.mail(email)
40+
code, message = server.rcpt(str(email))
41+
server.quit()
4142

42-
# Assume 250 as Success
43-
if code == 250:
44-
print("The email address",email,"is VALID")
45-
else:
46-
print("Invalid Email!")
43+
# Assume 250 as Success
44+
if code == 250:
45+
print("Check 3 (SMTP response) Passed")
46+
print(email,"is a VALID email address!")
47+
else:
48+
print("Check 3 FAILED! The user",email.split("@")[0],"does not exist, Invalid Email!")
49+
except socket.error as socketerror:
50+
print("Check 3 HALTED! The domain",domain,", either does not have an SMTP or have restricted access through external scripts")
4751

48-
email = input()
52+
#email = input()
53+
email = "mdsaaalik@gmail.com"
54+
domain = email.split("@")[-1]
4955
check_syntax(email)#CHECK1
50-
mxRecord = check_dns(email)#CHECK2
51-
check_response(email,mxRecord)#CHECK3
56+
mxRecord = check_dns(email,domain)#CHECK2
57+
check_response(email,domain,mxRecord)#CHECK3

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /