1

I am trying to verify emails by sending requests to SMTP servers. When I test in Linux, it works for 90% of emails. When I test in Windows, I did some analysis and like for 79% of emails will show the WinError10060 problem.

I tried using VPN, proxies and even turning off the firewall but the same problem will appear:

[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

Could this be from the firewall in the router or the internet provider blocking the port? But in the mean time, for 21% of emails I get answers like 250, 550 etc.

Here's the code:

        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)
Bese
  • 66
  • 10
  • Did you ever figure it out? – Stephen Jul 20 '18 at 21:37
  • 1
    They don't let me access on the router but it should be the problem with SMTP port being blocked (either in router or from the internet provider since I tried sending requests too much). But, I chose to execute the script in EC2 instance AWS. For this, I needed to contact AWS and request from them to remove limitations on SMTP port for my instance. After they removed limitations, I had no problem with executing the code! I hope this will help you too. – Bese Jul 23 '18 at 14:22

0 Answers0