Email Address Validation
The `validate-email` library (version 1.3, last updated in 2015) provides basic functionality to verify if an email address is valid, properly formatted, and optionally checks for the existence of its domain's MX record and the email address itself via an SMTP check. Due to its age, it is largely unmaintained. More robust and actively developed alternatives are recommended for modern Python projects.
Warnings
- deprecated The `validate-email` library (version 1.3) was last updated in 2015 and is largely unmaintained. It may not fully comply with modern RFC standards or integrate well with newer Python versions and asynchronous patterns. Consider using more actively maintained alternatives like `py3-validate-email` or `email-validator` for better support and features.
- gotcha Performing real-time MX record lookups (`check_mx=True`) and SMTP server verification (`verify=True`) involves network requests, which are inherently slow and can introduce significant latency to your application. This is often the primary bottleneck when validating many emails.
- breaking Using `verify=True` for bulk email verification can lead to your server's IP address being blacklisted by email providers (e.g., Gmail, Outlook). Frequent attempts to connect to SMTP servers for non-delivery purposes can be flagged as spamming activity.
- gotcha The `pyDNS` dependency, crucial for MX/SMTP checks, can be problematic to install or use on certain Python 3 environments due to conflicts with other DNS libraries (`dnspython`) or general compatibility issues with older versions of Python 3.
Install
-
pip install validate_email -
pip install validate_email pyDNS
Imports
- validate_email
from validate_email import validate_email
Quickstart
from validate_email import validate_email
# Basic syntax validation
is_valid_syntax = validate_email('test@example.com')
print(f"Syntax valid: {is_valid_syntax}")
# With MX record check (requires pyDNS)
is_valid_mx = validate_email('test@example.com', check_mx=True)
print(f"MX valid (requires pyDNS): {is_valid_mx}")
# With MX and SMTP verification (requires pyDNS)
is_valid_smtp = validate_email('test@example.com', check_mx=True, verify=True)
print(f"SMTP verified (requires pyDNS): {is_valid_smtp}")
# Example of an invalid email
is_invalid = validate_email('invalid-email')
print(f"Invalid email: {is_invalid}")