私は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ループはその世話をしているが、今では、リストの残りの部分を反復処理ではない上、電子メールにハングアップします。これはプロジェクトのためのものなので、動かすための助けに感謝します。