[Python] python: correct method verify if email exists

Discussão em 'Python' iniciado por Stack, Março 29, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to verify if an email actually exists by first resolving its dns, then check if the email is valid using the below code:

    email = test@cisco.com
    domain = email.split("@")[-1]
    records = dns.resolver.query(domain, 'MX')
    mxRecord = records[0].exchange
    mxRecord = str(mxRecord)
    server.connect(mxRecord)
    server.helo(host)
    server.mail('myemail@gmail.com')
    code, message = server.rcpt(str(email))
    server.quit()
    if code == 250:
    print('valid email', message)
    else:
    print('invalid email', message)


    This works few times, but when I send multiple request I get a message like:


    "5.7.1 Service unavailable, Client host [122.166.xxx.xxx] blocked using Spamhaus. To request removal from this list see http://www.spamhaus.org/lookup.lasso (AS160312312) [BL2NAM02FT12312.eop-nam02.prod.protection.outlook.com]'"
    ​

    I understand that they are trying to block my ip address as it thinks its spammy.

    Here are my questions:

    • Is there a right way to do this type of email validation, without getting marked as spam? Is it getting marked as spam as I am running the code on my system and just giving a dummy value for email like

    server.mail('myemail@gmail.com')
    ​
    • Is it possible to use some proxy to do this? My usecase require 100's of email addresses to be verified. I see some commercial api available for email validation, but it is not feasible for me at the moment.

    Continue reading...

Compartilhe esta Página