Package: email-validate
email-validateBase on@karolyi/py3-validate-emailemail-validate is a package for Python that check if an email is valid, not blacklisted, properly formatted and really exists.This module is for Python 3.6 and above!INSTALLATIONYou can install the package with pip:pip3 install email-validateUSAGEBasic usage:In [1]: from email_validate import validate, validate_or_fail

In [2]: validate(
   ...:     email_address='hello@00.pe',
   ...:     check_format=True,
   ...:     check_blacklist=True,
   ...:     check_dns=True,
   ...:     dns_timeout=10,
   ...:     check_smtp=False,
   ...:     smtp_debug=False)
Out[2]: False

In [3]: validate(
   ...:     email_address='joe.us.yk@gmail.com',
   ...:     check_format=True,
   ...:     check_blacklist=True,
   ...:     check_dns=True,
   ...:     dns_timeout=10,
   ...:     check_smtp=False,
   ...:     smtp_debug=False)
Out[3]: TrueParametersemail_address: the email address to checkcheck_format: check whether the email address has a valid structure; defaults toTruecheck_blacklist: check the email against the blacklist of domains downloaded fromDadouDatatemporary email data(daily update!!!); defaults toTruecheck_dns: check the DNS mx-records, defaults toTruedns_timeout: seconds until DNS timeout; defaults to 10 secondscheck_smtp: check whether the email actually exists by initiating an SMTP conversation; defaults toTruesmtp_timeout: seconds until SMTP timeout; defaults to 10 secondssmtp_helo_host: the hostname to use in SMTP HELO/EHLO; if set toNone(the default), the fully qualified domain name of the local host is usedsmtp_from_address: the email address used for the sender in the SMTP conversation; if set toNone(the default), theemail_addressparameter is used as the sender as wellsmtp_debug: activatesmtplib's debug output which always goes to stderr; defaults toFalseResultThe functionvalidate()returns the following results:TrueAll requested checks were successful for the given email address.FalseAt least one of the requested checks failed for the given email address.NoneNone of the requested checks failed, but at least one of them yielded an ambiguous result. Currently, the SMTP check is the only check which can actually yield an ambigous result.Getting more informationThe functionvalidate_or_fail()works exactly likevalidate(), except that it raises an exception in the case of validation failure and ambiguous result instead of returningFalseorNone, respectively.All these exceptions descend fromEmailValidationError. Please see below for the exact exceptions raised by the various checks. Note that all exception classes are defined in the modulevalidate_email.exceptions.Please note thatSMTPTemporaryErrorindicates an ambigous check result rather than a check failure, so if you usevalidate_or_fail(), you probably want to catch this exception.The checksBy default, all checks are enabled, but each of them can be disabled by one of thecheck_...parameters. Note that, however,check_smtpimpliescheck_dns.check_formatCheck whether the given email address conforms to the general format requirements of valid email addresses.validate_or_fail()raisesAddressFormatErroron any failure of this test.check_blacklistCheck whether the domain part of the given email address (the part behind the "@") is known as a disposable and temporary email address domain. These are often used to register dummy users in order to spam or abuse some services.A list of such domains is maintained atDadouDatatemporary email data(daily update!!!), and this module uses that list.validate_or_fail()raisesDomainBlacklistedErrorif the email address belongs to a blacklisted domain.check_dnsCheck whether there is a valid list of servers responsible for delivering emails to the given email address.First, a DNS query is issued for the email address' domain to retrieve a list of all MX records. That list is then stripped of duplicates and malformatted entries. If at the end of this procedure, at least one valid MX record remains, the check is considered successful.On failure of this check,validate_or_fail()raises one of the following exceptions, all of which descend fromDNSError:DomainNotFoundErrorThe domain of the email address cannot be found at all.NoNameserverErrorThere is no nameserver for the domain.DNSTimeoutErrorA timeout occured when querying the nameserver. Note that the timeout period can be changed with thedns_timeoutparameter.DNSConfigurationErrorThe nameserver is misconfigured.NoMXErrorThe nameserver does not list any MX records for the domain.NoValidMXErrorThe nameserver lists MX records for the domain, but none of them is valid.check_smtpCheck whether the given email address exists by simulating an actual email delivery.A connection to the SMTP server identified through the domain's MX record is established, and an SMTP conversation is initiated up to the point where the server confirms the existence of the email address. After that, instead of actually sending an email, the conversation is cancelled.The module will try to negotiate a TLS connection with STARTTLS, and silently fall back to an unencrypted SMTP connection if the server doesn't support it.If the SMTP server replies to theRCPT TOcommand with a code 250 (success) response, the check is considered successful.If the SMTP server replies with a code 5xx (permanent error) response at any point in the conversation, the check is considered failed.If the SMTP server cannot be connected, unexpectedly closes the connection, or replies with a code 4xx (temporary error) at any stage of the conversation, the check is considered ambiguous.If there is more than one valid MX record for the domain, they are tried in order of priority until the first time the check is either successful or failed. Only in case of an ambiguous check result, the next server is tried, and only if the check result is ambiguous for all servers, the overall check is considered ambigous as well.On failure of this check or on ambiguous result,validate_or_fail()raises one of the following exceptions, all of which descend fromSMTPError:AddressNotDeliverableErrorThe SMTP server permanently refused the email address. Technically, this means that the server replied to theRCPT TOcommand with a code 5xx response.SMTPCommunicationErrorThe SMTP server refused to even let us get to the point where we could ask it about the email address. Technically, this means that the server sent a code 5xx response either immediately after connection, or as a reply to theEHLO(orHELO) orMAIL FROMcommands.SMTPTemporaryErrorA temporary error occured during the check for all available MX servers. This is considered an ambigous check result. For example, greylisting is a frequent cause for this.All of the above three exceptions provide further detail about the error response(s) in the exception's instance variableerror_messages.Update data sourceThe package contains an auto-updater for downloading and updating the built-in blacklist.txt. It will run on each module load (and installation), but will try to update the content only if the file is older than 5 days, and if the content is not the same that's already downloaded.The update can be triggered manually:from validate_email.updater import update_builtin_blacklist

update_builtin_blacklist(force: bool = False, background: bool = True,
    callback: Callable = None) -> Optional[Thread]force: forces the update even if the downloaded/installed file is fresh enough.background: starts the update in aThreadso it won't make your code hang while it's updating. If you set this to true, the function will return the Thread used for starting the update so you canjoin()it if necessary.callback: An optionalCallable(function/method) to be called when the update is done.TODOfixed domainblacklist data source auto update error.Read the FAQ