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 27a4b12

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

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

‎Email-Validator/README.md‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<h1 align="center">Email Validator</h1>
2+
A simple program which checks for Email Address Validity in three simple checks
3+
4+
---------------------------------------------------------------------
5+
## How it works
6+
7+
- Syntax check, Checks for basic email address syntax using Regex
8+
9+
- DNS check, Checks for domain validity and retrieving record names
10+
11+
- 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.
12+
13+
#### By [Md Salik](https://github.com/saaalik)
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
from dns import resolver
2+
import smtplib
3+
import socket
4+
import re
5+
6+
#FIRST CHECK
7+
def check_syntax(email):
8+
regex = r'^[a-z0-9]+[\._]?[a-z0-9]+[@]\w+[.]\w{2,3}$'
9+
if(re.search(regex,email)):
10+
pass
11+
else:
12+
print("Invalid Email! Bad Syntax")
13+
exit()
14+
15+
#SECOND CHECK
16+
def check_dns(email):
17+
domain = email.split("@")[-1]
18+
try:
19+
records = resolver.resolve(domain, 'MX')
20+
mxRecord = str(records[0].exchange)
21+
return mxRecord
22+
except:
23+
print("Invalid Email! The domain",domain,"does not exist")
24+
exit()
25+
26+
#THIRD CHECK
27+
def check_response(email, mxRecord):
28+
# Get local server hostname
29+
host = socket.gethostname()
30+
31+
# SMTP lib setup (use debug level for full output)
32+
server = smtplib.SMTP()
33+
server.set_debuglevel(0)
34+
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()
41+
42+
# Assume 250 as Success
43+
if code == 250:
44+
print("The email address",email,"is VALID")
45+
else:
46+
print("Invalid Email!")
47+
48+
email = input()
49+
check_syntax(email)#CHECK1
50+
mxRecord = check_dns(email)#CHECK2
51+
check_response(email,mxRecord)#CHECK3

0 commit comments

Comments
(0)

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