2019-03-01 23:32:03 +01:00
.. image :: https://travis-ci.org/karolyi/py3-validate-email.svg?branch=master
:target: https://travis-ci.org/karolyi/py3-validate-email
2019-09-25 20:10:11 +02:00
.. image :: https://bmc-cdn.nyc3.digitaloceanspaces.com/BMC-button-images/custom_images/orange_img.png
2020-01-20 11:36:13 +01:00
:target: https://buymeacoff.ee/karolyi
2019-03-01 23:32:03 +01:00
2019-03-02 03:26:58 +01:00
============================
2019-03-01 23:32:03 +01:00
py3-validate-email
2019-03-02 03:26:58 +01:00
============================
2012-04-07 23:05:57 +02:00
2019-11-24 18:20:03 +01:00
py3-validate-email is a package for Python that check if an email is valid, not blacklisted, properly formatted and really exists.
2012-04-07 23:05:57 +02:00
2019-03-02 00:59:23 +01:00
This module is for Python 3.6 and above!
2012-04-07 23:05:57 +02:00
INSTALLATION
2019-03-02 03:26:58 +01:00
============================
2012-04-07 23:05:57 +02:00
2020-04-11 16:04:27 +02:00
You can install the package with pip::
2012-04-07 23:05:57 +02:00
2020-04-11 16:04:27 +02:00
python -m pip install py3-validate-email
2012-04-07 23:05:57 +02:00
USAGE
2019-03-02 03:26:58 +01:00
============================
2012-04-07 23:05:57 +02:00
Basic usage::
2019-03-01 23:32:03 +01:00
from validate_email import validate_email
2020-06-09 12:34:51 +02:00
is_valid = validate_email(email_address='example@example.com', check_regex=True, check_mx=True, from_address='my@from.addr.ess', helo_host='my.host.name', smtp_timeout=10, dns_timeout=10, use_blacklist=True, debug=False)
2012-04-07 23:05:57 +02:00
2019-03-02 03:30:58 +01:00
:code: `check_regex` will check will the email address has a valid structure and defaults to True
2012-04-07 23:05:57 +02:00
2019-03-02 03:30:58 +01:00
:code:`check_mx`: check the mx-records and check whether the email actually exists
2021-02-22 14:32:56 +01:00
:code:`from_address`: the email address the probe will be sent from
2019-03-02 03:30:58 +01:00
2021-02-22 14:32:56 +01:00
:code:`helo_host`: the host to use in SMTP HELO when checking for an email
2019-03-02 04:00:12 +01:00
2019-03-02 03:30:58 +01:00
:code:`smtp_timeout`: seconds until SMTP timeout
2019-05-25 14:36:20 +02:00
:code:`dns_timeout`: seconds until DNS timeout
2019-05-25 13:59:27 +02:00
2019-03-02 04:07:12 +01:00
:code:`use_blacklist`: use the blacklist of domains downloaded from https://github.com/martenson/disposable-email-domains
2012-04-07 23:05:57 +02:00
2020-11-19 14:26:52 +01:00
:code:`debug`: emit debug/warning messages while checking email
2020-06-09 12:34:51 +02:00
2021-02-11 17:49:29 +01:00
:code:`skip_smtp`: (default :code:`False`) skip the SMTP conversation with the server, after MX checks. Will automatically be set to :code:`True` when :code:`check_mx` is :code:`False`!
2021-02-11 15:48:35 +01:00
2021-02-28 15:01:37 +01:00
The function :code: `validate_email_or_fail()` works exactly like :code: `validate_email` , except that it raises an exception in the case of validation failure and ambiguous result instead of returning :code: `False` or :code: `None` , respectively.
2020-04-08 23:56:49 +02:00
2020-10-11 13:51:37 +02:00
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.
2019-11-24 18:20:03 +01:00
Auto-updater
============================
2020-04-11 16:04:27 +02:00
The 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.
2020-04-11 14:29:54 +02:00
The update can be triggered manually::
2020-04-11 14:21:52 +02:00
from validate_email.updater import update_builtin_blacklist
update_builtin_blacklist(force: bool = False, background: bool = True,
2020-04-11 16:04:27 +02:00
callback: Callable = None) -> Optional[Thread]
2020-04-11 14:21:52 +02:00
2020-04-11 14:29:54 +02:00
:code:`force`: forces the update even if the downloaded/installed file is fresh enough.
2020-04-11 14:21:52 +02:00
2020-04-11 14:29:54 +02:00
:code:`background`: starts the update in a ``Thread`` so 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 can ``join()`` it if necessary.
2020-04-11 14:21:52 +02:00
2020-04-11 16:04:27 +02:00
:code:`callback`: An optional `Callable` (function/method) to be called when the update is done.
2019-11-24 18:20:03 +01:00
2021-03-01 11:56:09 +01:00
Read the FAQ_!
============================
.. _FAQ: https://github.com/karolyi/py3-validate-email/blob/master/FAQ.md