我試圖使用我發現的腳本ping通電子郵件,以確保它們存在。電子郵件Ping掛在電子郵件
with open(input_list, 'r') as f:
reader = csv.reader(f)
for row in reader:
address = row[0]
person_name = row[1]+' '+row[2]
company = row[4]
match = re.match('^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$', address)
print("Email for ", person_name)
print(address)
if match == None:
synt = 'Bad Syntax'
warnings.warn(address + " has bad syntax.")
else:
synt = 'Good syntax'
dom = re.search("@(.*)$", address).group(1)
print(dom)
try:
records = dns.resolver.query(dom, 'MX')
mxRecord = records[0].exchange
mxRecord = str(mxRecord)
except:
warnings.warn("Issue contacting domain")
pass
# Get local server hostname
host = socket.gethostname()
# SMTP lib setup (use debug level for full output)
server = smtplib.SMTP('smtp-mail.outlook.com',587)#will need this for mail sending
while True:
try:
server.set_debuglevel(0)
# SMTP Conversation
server.connect(mxRecord)
server.helo(host)
server.mail('[email protected]')
code, message = server.rcpt(str(address))
server.quit()
if code == 250:
print('Success')
new_row = [address, person_name, company, synt, 'Ping Successful']
email_data.append(new_row)
with open('cseresult2.csv', 'a+', newline='') as mess:
writ = csv.writer(mess, dialect='excel')
writ.writerow(email_data[-1])
else:
print('Bad')
new_row = [address, person_name, company, synt, 'Ping Bounced']
email_data.append(new_row)
with open('cseresult2.csv', 'a+', newline='') as mess:
writ = csv.writer(mess, dialect='excel')
writ.writerow(email_data[-1])
except:
continue
break
print()
print('================')
print()
time.sleep(3)
該代碼工作大多好。然而,跳出while循環,我得到了很多超時錯誤:
TimeoutError: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
while循環已經慎重了,但現在它掛在電子郵件上通過列表的其餘部分不重複。這是一個項目,所以任何幫助,讓它移動,將不勝感激。