You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add optional argument dns_resolver to validate_email. If provided it will be used instead of the default resolver. The provided resolver can have a configured cache and custom timeout.
Co-authored-by: Joshua Tauberer <[email protected]>
Copy file name to clipboardExpand all lines: README.md
+18-11
Original file line number
Diff line number
Diff line change
@@ -14,7 +14,7 @@ Key features:
14
14
login forms or other uses related to identifying users.
15
15
* Gives friendly error messages when validation fails (appropriate to show
16
16
to end users).
17
-
* (optionally) Checks deliverability: Does the domain name resolve?
17
+
* (optionally) Checks deliverability: Does the domain name resolve? And you can override the default DNS resolver.
18
18
* Supports internationalized domain names and (optionally)
19
19
internationalized local parts.
20
20
* Normalizes email addresses (super important for internationalized
@@ -69,23 +69,27 @@ This validates the address and gives you its normalized form. You should
69
69
put the normalized form in your database and always normalize before
70
70
checking if an address is in your database.
71
71
72
-
The validator will accept internationalized email addresses, but email
73
-
addresses with non-ASCII characters in the *local* part of the address
74
-
(before the @-sign) require the
75
-
[SMTPUTF8](https://tools.ietf.org/html/rfc6531) extension which may not
76
-
be supported by your mail submission library or your outbound mail
77
-
server. If you know ahead of time that SMTPUTF8 is not supported then
78
-
**add the keyword argument allow\_smtputf8=False to fail validation for
79
-
addresses that would require SMTPUTF8**:
72
+
When validating many email addresses or to control the timeout (the default is 15 seconds), create a caching [dns.resolver.Resolver](https://dnspython.readthedocs.io/en/latest/resolver-class.html) to reuse in each call:
The validator will accept internationalized email addresses, but not all
84
+
mail systems can send email to an addresses with non-ASCII characters in
85
+
the *local* part of the address (before the @-sign). See the `allow_smtputf8`
86
+
option below.
87
+
88
+
85
89
Overview
86
90
--------
87
91
88
-
The module provides a single function `validate_email(email_address)` which
92
+
The module provides a function `validate_email(email_address)` which
89
93
takes an email address (either a `str` or ASCII `bytes`) and:
90
94
91
95
- Raises a `EmailNotValidError` with a helpful, human-readable error
@@ -128,6 +132,9 @@ shown):
128
132
129
133
`allow_empty_local=False`: Set to `True` to allow an empty local part (i.e.
130
134
`@example.com`), e.g. for validating Postfix aliases.
135
+
136
+
`dns_resolver=None`: Pass an instance of [dns.resolver.Resolver](https://dnspython.readthedocs.io/en/latest/resolver-class.html) to control the DNS resolver including setting a timeout and [a cache](https://dnspython.readthedocs.io/en/latest/resolver-caching.html). The `caching_resolver` function shown above is a helper function to construct a dns.resolver.Resolver with a [LRUCache](https://dnspython.readthedocs.io/en/latest/resolver-caching.html#dns.resolver.LRUCache). Reuse the same resolver instance across calls to `validate_email` to make use of the cache.
0 commit comments