Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/305.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python,检查是否存在不存在的电子邮件_Python_Python 3.x_Email_Smtp - Fatal编程技术网

Python,检查是否存在不存在的电子邮件

Python,检查是否存在不存在的电子邮件,python,python-3.x,email,smtp,Python,Python 3.x,Email,Smtp,我是python中smtp的新手,我想写一个脚本来检查电子邮件是否有效 我写了这个脚本,但仍然有错误,比如超时或错误:套接字错误:0x06:TTL过期,我不知道为什么:/ domaine = email.split('@')[1] try: mx_hosts = dns.resolver.query(domaine, 'MX') except Exception: list_not_email.append(email) break for mx in mx_hosts

我是python中smtp的新手,我想写一个脚本来检查电子邮件是否有效

我写了这个脚本,但仍然有错误,比如
超时
错误:套接字错误:0x06:TTL过期
,我不知道为什么:/

domaine = email.split('@')[1]
try:
    mx_hosts = dns.resolver.query(domaine, 'MX')
except Exception:
    list_not_email.append(email)
    break

for mx in mx_hosts:

    exchange = str(mx.exchange)

    # .. if this doesn't raise an exception it is a valid MX host...
    try:
        smtp = smtplib.SMTP(exchange)
        # smtp.connect(exchange)

        smtp.helo()  # send the HELO command
        smtp.mail('webbot92@gmail.com')  # send the MAIL command
        resp = smtp.rcpt(email)
        print(resp)
        if resp[0] == 250:  # check the status code
            print('Email valid')
        elif resp[0] == 550:
            print('Email not valid')
        elif resp[0] == 450:
            print('Error')

    except smtplib.SMTPConnectError:
        continue  # try the next MX server in list

对不起,我忘记使用代理socks。设置默认代理socks(socks.SOCKS5,proxy,1090,True,user,password)socks。wrapmodule(smtplib)我的答案有帮助吗?很多,ty:D!!但我不认为“pyIsemail”或“Flander”真的会检查电子邮件是否存在,那只是检查DNS和MX记录。这是SMTP内置的一个限制,可以阻止垃圾邮件发送者检查电子邮件是否存在。