def validate_mx(server, domain):
    try:
        if server in MX_RECORD_CACHE:
            return MX_RECORD_CACHE[server]
        smtp = smtplib.SMTP(timeout=10)
        smtp.connect(server)
        status, _ = smtp.helo()
        if status != 250:
            smtp.quit()
            print "%s answer: %s - %s" % (server, status, _)
        smtp.mail('')
        status, _ = smtp.rcpt("invalid@"+domain)
        if status == 250:
            smtp.quit()
            MX_RECORD_CACHE[server] = True
            return True
        print "%s answer: %s - %s" % (server, status, _)
        smtp.quit()
    except smtplib.SMTPServerDisconnected as e:  # Server not permits verify user
        print "%s disconnected. [%s]" % (server, e)
    except smtplib.SMTPConnectError as e:
        print "Unable to connect to %s. [%s]" % (server, e)
    except socket.timeout as e:
        print "Timedout connecting to %s. [%s]" % (server, e)
    MX_RECORD_CACHE[server] = False
    return False        

# Lookup a domain and get its mailserver
dataset/ETHPy150Open tatanus/SPF/spf/core/emails.py/validate_mx/original