
Product
Introducing Tier 1 Reachability: Precision CVE Triage for Enterprise Teams
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
A comprehensive email validation library that provides domain suggestions, disposable email detection, and MX record validation with a focus on security and user experience.
pip install email-safeguard
from email_safeguard.validator import EmailSafeguard
validator = EmailSafeguard()
result = validator.validate("user@gmial.com")
if result.is_valid:
if result.suggestions:
print(f"Email is valid but did you mean: {result.suggestions.get('domain')}?")
else:
print("Email is valid!")
else:
print(f"Error: {result.message}")
validator = EmailSafeguard(
check_mx=True, # Enable MX record validation
allow_disposable=False, # Reject disposable emails
suggest_corrections=True, # Suggest corrections for typos
max_distance=2, # Maximum edit distance for suggestions
dns_timeout=3.0, # DNS query timeout in seconds
dns_retries=2, # Number of retry attempts for DNS queries
retry_delay=1.0 # Delay between retries in seconds
)
You can control how the validator handles MX record timeouts:
# Strict validation (timeouts treated as invalid)
result = validator.validate("example@domain.com", skip_mx_on_timeout=False)
# Lenient validation (timeouts treated as valid with warning)
result = validator.validate("example@domain.com", skip_mx_on_timeout=True)
if result.result == ValidationResult.TIMEOUT:
print("DNS query timed out")
from email_safeguard.validator import EmailSafeguard, ValidationResult
validator = EmailSafeguard()
result = validator.validate("user@tempmail.com")
# Check the validation result
if result.result == ValidationResult.VALID:
print("Email is valid!")
elif result.result == ValidationResult.DISPOSABLE:
print("Disposable emails not allowed")
elif result.result == ValidationResult.INVALID_DOMAIN:
if result.suggestions and 'domain' in result.suggestions:
print(f"Invalid domain. Did you mean: {result.suggestions['domain']}?")
elif result.result == ValidationResult.NO_MX_RECORD:
print("Domain has no mail server")
elif result.result == ValidationResult.TIMEOUT:
print("MX record check timed out")
The library provides several validation result types:
from email_safeguard.validator import ValidationResult
# Available validation results:
# ValidationResult.VALID - Email is valid
# ValidationResult.INVALID_FORMAT - Email format is invalid
# ValidationResult.INVALID_DOMAIN - Domain is invalid
# ValidationResult.INVALID_TLD - Top-level domain is invalid
# ValidationResult.DISPOSABLE - Domain is a disposable email provider
# ValidationResult.NO_MX_RECORD - Domain has no MX records
# ValidationResult.TIMEOUT - MX record check timed out
The validate()
method returns a ValidationResponse
object with the following attributes:
class ValidationResponse:
is_valid: bool # Whether the email is valid
result: ValidationResult # The specific validation result
message: str # A descriptive message
suggestions: Optional[Dict[str, str]] # Suggested corrections if any
Adjust DNS query settings for your needs:
# For faster validation with less reliability
validator = EmailSafeguard(
dns_timeout=1.0, # Short timeout
dns_retries=1, # Single attempt
retry_delay=0.5 # Short retry delay
)
# For more reliable validation
validator = EmailSafeguard(
dns_timeout=5.0, # Longer timeout
dns_retries=3, # More retries
retry_delay=1.0 # Standard retry delay
)
The library uses three customizable data files:
popular_domains.txt
: Common email domainspopular_tlds.txt
: Valid top-level domainsdisposable_domains.txt
: Known disposable email providersvalidator = EmailSafeguard(data_dir="path/to/data/directory")
# Run all tests
python -m pytest
# Run with coverage
python -m pytest --cov=email_safeguard
mypy email_safeguard
git checkout -b feature/amazing-feature
)git commit -m 'Add amazing feature'
)git push origin feature/amazing-feature
)This project is licensed under the MIT License - see the LICENSE file for details.
Chukwuka Ibejih (chukaibejih@gmail.com)
Built with:
If you find this library helpful, please give it a ⭐!
FAQs
A Python library for validating and suggesting corrections for email addresses.
We found that email-safeguard demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
Research
/Security News
Ongoing npm supply chain attack spreads to DuckDB: multiple packages compromised with the same wallet-drainer malware.
Security News
The MCP Steering Committee has launched the official MCP Registry in preview, a central hub for discovering and publishing MCP servers.