Skip to content

Commit da48fd1

Browse files
committed
Fix the returned implicit MX record when there is a fallback
The object returned by validate_email returns the queried MX records when deliverability checks are run. When there is an implicit MX record (no MX record but an A or AAAA record), the value is a single entry that points to the host, not a list of the A or AAAA values. SMTP 5321 5.1: > If an empty list of MXs is returned, the address is treated as if it was associated with an implicit MX R, with a preference of 0, pointing to that host.
1 parent d6d3d15 commit da48fd1

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
In Development
22
--------------
33

4+
* When a domain name has no MX record but does have an A or AAAA record, the mx field in the object returned by validate_email incorrectly held the IP addresses rather than the domain itself.
45
* Fixes in tests.
56

67
2.1.1 (February 26, 2024)

email_validator/deliverability.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def validate_email_deliverability(domain: str, domain_i18n: str, timeout: Option
6060
# If there was no MX record, fall back to an A record. (RFC 5321 Section 5)
6161
try:
6262
response = dns_resolver.resolve(domain, "A")
63-
deliverability_info["mx"] = [(0, str(r)) for r in response]
63+
deliverability_info["mx"] = [(0, domain)]
6464
deliverability_info["mx_fallback_type"] = "A"
6565

6666
except dns.resolver.NoAnswer:
@@ -69,7 +69,7 @@ def validate_email_deliverability(domain: str, domain_i18n: str, timeout: Option
6969
# (It's unclear if SMTP servers actually do this.)
7070
try:
7171
response = dns_resolver.resolve(domain, "AAAA")
72-
deliverability_info["mx"] = [(0, str(r)) for r in response]
72+
deliverability_info["mx"] = [(0, domain)]
7373
deliverability_info["mx_fallback_type"] = "AAAA"
7474

7575
except dns.resolver.NoAnswer as e:

tests/test_deliverability.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
'domain,expected_response',
1515
[
1616
('gmail.com', {'mx': [(5, 'gmail-smtp-in.l.google.com'), (10, 'alt1.gmail-smtp-in.l.google.com'), (20, 'alt2.gmail-smtp-in.l.google.com'), (30, 'alt3.gmail-smtp-in.l.google.com'), (40, 'alt4.gmail-smtp-in.l.google.com')], 'mx_fallback_type': None}),
17-
('pages.github.com', {'mx': [(0, '185.199.108.153'), (0, '185.199.109.153'), (0, '185.199.111.153'), (0, '185.199.110.153')], 'mx_fallback_type': 'A'}),
17+
('pages.github.com', {'mx': [(0, 'pages.github.com')], 'mx_fallback_type': 'A'}),
1818
],
1919
)
2020
def test_deliverability_found(domain, expected_response):

0 commit comments

Comments
 (0)