-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_email.py
83 lines (66 loc) · 2.32 KB
/
check_email.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
70
71
72
73
74
75
76
77
#!/usr/local/bin/python
# -*- coding: utf-8 -*-
import pandas as pd
import sys
import smtplib
import csv
import dns.resolver
from multiprocessing import Pool
import time
from generate_emails import emails
import socket
reload(sys)
sys.setdefaultencoding('utf-8')
df = pd.read_excel('15000_contacts/all_new.xlsx')
emails = emails()
def write_csv(data): # write to csv
with open('15000_contacts/test.csv', 'a') as f:
csv.writer(f).writerow((data['num'],
data['email']))
def checking_emails(elements): # checking all emails
sur, name, patr, dom, num = elements
global emails
test_email = 'qweasdzxc123' + '@' + str(dom)
email_status = 'none'
trying = 0
resolver = dns.resolver.Resolver()
resolver.timeout = 60
resolver.lifetime = 60
while email_status is 'none':
try:
print(dom)
mx_record = str(emails.get_mx(dom).split(' ')[1])
if emails.check_email(test_email, mx_record) == 250:
email_status = 'server_is_lying'
break
else:
for email in emails.generate_email(sur, name, patr, dom):
if emails.check_email(email, mx_record) == 250:
email_status = email
data = {'num': num,
'email': email_status}
return data
else:
continue
email_status = 'not_found'
except (dns.resolver.NXDOMAIN, dns.resolver.NoNameservers, dns.name.LabelTooLong):
email_status = 'no_dns'
except (smtplib.SMTPServerDisconnected, socket.error, dns.resolver.NoAnswer, dns.exception.Timeout):
trying += 1
if trying < 3:
time.sleep(5)
pass
else:
email_status = 'error'
break
data = {'num': num,
'email': email_status}
return data
def make_all(inputs):
data = checking_emails(inputs)
write_csv(data)
if __name__ == '__main__':
pool = Pool(processes=40)
inputs = zip(df.sur_eng.values.tolist(), df.name_eng.values.tolist(), df.patr_eng.values.tolist(), df.domain.values.tolist(), df.number.values.tolist())
print pool.map(make_all, inputs)
pool.terminate()