-
Notifications
You must be signed in to change notification settings - Fork 0
/
auth.py
69 lines (67 loc) · 2.46 KB
/
auth.py
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env python
import smtplib
import re
def auth(username, password, auth_type):
if auth_type == '1':
parse = re.search("([\w\.]*[\w])[@]([\w.]*[\w])", username)
if parse == None:
result = "Invalid email address"
return result
return "S"
uname = parse.group(1)
domain_name = parse.group(2)
try:
if domain_name == "gmail.com":
mailserver = smtplib.SMTP("smtp.gmail.com", 587)
mailserver.ehlo()
mailserver.starttls()
mailserver.ehlo()
(code, msgstr) = mailserver.login(username, password)
if code == 235:
result = "S"
else:
result = msgstr
mailserver.close()
elif domain_name == "yahoo.com":
mailserver = smtplib.SMTP("smtp.mail.yahoo.com")
mailserver.ehlo()
# mailserver.starttls()
mailserver.ehlo()
(code, msgstr) = mailserver.login(username, password)
if code == 235:
result = "S"
else:
result = msgstr
mailserver.close()
elif domain_name == "hotmail.com":
mailserver = smtplib.SMTP("smtp.live.com", 25)
mailserver.ehlo()
mailserver.starttls()
mailserver.ehlo()
(code, msgstr) = mailserver.login(username, password)
if code == 235:
result = "S"
else:
result = msgstr
mailserver.close()
elif domain_name == "rediffmail.com":
mailserver = smtplib.SMTP("smtp.rediffmail.com", 25)
# mailserver.ehlo()
# mailserver.starttls()
mailserver.ehlo()
(code, msgstr) = mailserver.login(username, password)
if code == 235:
result = "S"
else:
result = msgstr
mailserver.close()
else:
print("Sorry, " + domain_name + " is not supported. Currently only GMail authentication is available\n")
result = "Unsupported"
except Exception as e:
result = e
elif auth_type == '2':
result = "LDAP coming soon"
else:
result = "Invalid"
return result