我正在尝试通过将请求发送到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)