1

我正在尝试通过向 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)
4

0 回答 0