Skip to content

Commit a880eb8

Browse files
committed
Merge main branch into dev branch
2 parents 647a0f9 + 65b2744 commit a880eb8

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

README.md

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -75,26 +75,27 @@ account in your application, you might do this:
7575
from email_validator import validate_email, EmailNotValidError
7676

7777
email = "my+address@mydomain.tld"
78+
is_new_account = True # False for login pages
7879

7980
try:
80-
# Validate & take the normalized form of the email
81-
# address for all logic beyond this point (especially
81+
# Check that the email address is valid.
82+
validation = validate_email(email, check_deliverability=is_new_account)
83+
84+
# Take the normalized form of the email address
85+
# for all logic beyond this point (especially
8286
# before going to a database query where equality
83-
# does not take into account normalization).
84-
email = validate_email(email).email
87+
# may not take into account Unicode normalization).
88+
email = validation.email
8589
except EmailNotValidError as e:
86-
# email is not valid, exception message is human-readable
90+
# Email is not valid.
91+
# The exception message is human-readable.
8792
print(str(e))
8893
```
8994

9095
This validates the address and gives you its normalized form. You should
9196
**put the normalized form in your database** and always normalize before
92-
checking if an address is in your database.
93-
94-
The validator will accept internationalized email addresses, but not all
95-
mail systems can send email to an addresses with non-English characters in
96-
the *local* part of the address (before the @-sign). See the `allow_smtputf8`
97-
option below.
97+
checking if an address is in your database. When using this in a login form,
98+
set `check_deliverability` to `False` to avoid unnecessary DNS queries.
9899

99100
Usage
100101
-----
@@ -147,7 +148,7 @@ The `validate_email` function also accepts the following keyword arguments
147148
require the
148149
[SMTPUTF8](https://tools.ietf.org/html/rfc6531) extension. You can also set `email_validator.ALLOW_SMTPUTF8` to `False` to turn it off for all calls by default.
149150

150-
`check_deliverability=True`: Set to `False` to skip the domain name DNS record checks. You can also set `email_validator.CHECK_DELIVERABILITY` to `False` to turn it off for all calls by default.
151+
`check_deliverability=True`: Set to `False` to skip the domain name DNS record checks. It is recommended to pass `False` when performing validation for login pages (but not account creation pages) since re-validation of the domain by querying DNS at every login is probably undesirable. You can also set `email_validator.CHECK_DELIVERABILITY` to `False` to turn it off for all calls by default.
151152

152153
`allow_empty_local=False`: Set to `True` to allow an empty local part (i.e.
153154
`@example.com`), e.g. for validating Postfix aliases.

0 commit comments

Comments
 (0)