SMTP サーバーにリクエストを送信して電子メールを検証しようとしています。Linux でテストしたところ、90% の電子メールで機能しました。Windows でテストしたとき、いくつかの分析を行ったところ、電子メールの 79% でWinError10060の問題が表示されます。
VPN、プロキシを使用して、ファイアウォールをオフにしてみましたが、同じ問題が発生します。
[WinError 10060] 接続先が一定時間後に適切に応答しなかったため、接続試行が失敗したか、接続されたホストが応答しなかったために確立された接続が失敗しました
これは、ルーターのファイアウォールまたはインターネット プロバイダーがポートをブロックしている可能性がありますか? しかし、その間、メールの 21% で 250、550 などの回答が得られます。
コードは次のとおりです。
for email in rows:
email = email[0]
start = time.time()
if(email[-3:] == 'png'):
pass
else:
counter += 1
maildomain = email.split("@")[-1]
nstoken = "mail exchanger = "
mailserver = ""
mailservers = []
# Checking for domain names
# Command: nslookup -type=mx [mx server here]
plines = os.popen("nslookup -type=mx " + maildomain).readlines()
for pline in plines:
if nstoken in pline:
mailserver = pline.split(nstoken)[1].strip()
# No need this line in Windows environment
mailserver = mailserver.split(" ")[-1]
mailservers.append(mailserver)
invalid_emails = [550, 551, 553]
cannot_verify_emails = [450, 451, 452]
if mailservers == []:
email_result = "Invalid"
code_result = 000
print("No mail servers found")
else:
i = mailservers[0]
print("i: ", mailservers[0])
try:
# timeout = 10
# socket.setdefaulttimeout(timeout)
s = smtplib.SMTP(i)
# Identifying to an ESMTP server
# Command helo hi / ehlo hi
rep1 = s.ehlo()
print("rep1: ", rep1)
if rep1[0] == 250:
rep2 = s.mail("grencir1982@teleworm.us")
print("rep2: ", rep2)
if rep2[0] == 250:
rep3 = s.rcpt(email)
print("rep3: ", rep3)
if rep3[0] == 250:
print(email, " is valid, " + str(rep3[0]))
email_result = "Valid"
elif rep3[0] in cannot_verify_emails:
print(email, " verification not allowed" + str(rep3[0]))
email_result = "Server disallows verification or user mailbox is currently unavailable"
elif rep3[0] in invalid_emails:
print(email, " doesn't exist " + str(rep3[0]))
email_result = "Invalid"
else:
print(email, " response, " + str(rep3[0]))
email_result = "Other response"
code_result = str(rep3[0])
else:
print("rep2: s.rcpt not working")
email_result = "Other response"
else:
print("rep1: s.mail not working")
email_result = "Other response: Probably IP Blacklisted"
s.quit()
except socket.timeout:
email_result = "Socket Timeout Exception"
code_result = 000
print("Socket Timeout")
pass
except Exception as e:
email_result = str(e)
code_result = 000
print(e)