Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
A Python library for validating and suggesting corrections for email addresses.
A robust email validation library with domain and TLD suggestions, disposable email detection, and MX record validation.
Validates email format using Django's built-in validators.
Detects disposable email addresses.
Suggests corrections for common domain and TLD typos.
Checks for valid MX records for the domain.
To install the library, use pip:
pip install email-safeguard
Here's an example of how to use the EmailValidator
class:
from email_validator.validator import EmailValidator
validator = EmailValidator()
result = validator.validate("user@example.com")
if result["valid"]:
print("Email is valid!")
else:
print("Error:", result["error"])
You can customize the lists of popular domains, TLDs, and disposable domains by providing your own text files:
validator = EmailValidator(
domains_file='path/to/custom_domains.txt',
tlds_file='path/to/custom_tlds.txt',
disposable_file='path/to/custom_disposable_domains.txt'
)
The library uses three data files for validation:
popular_domains.txt: A list of popular email domains.
popular_tlds.txt: A list of popular top-level domains (TLDs).
disposable_domains.txt: A list of known disposable email domains.
Each file should contain one entry per line.
popular_domains.txt
gmail.com
yahoo.com
outlook.com
hotmail.com
popular_tlds.txt
com
net
org
edu
disposable_domains.txt
mailinator.com
10minutemail.com
Here's a more detailed example demonstrating all features:
import os
from email_validator import EmailValidator
# Initialize the validator with custom data files
validator = EmailValidator(
domains_file='data/popular_domains.txt',
tlds_file='data/popular_tlds.txt',
disposable_file='data/disposable_domains.txt'
)
emails = [
"valid.email@gmail.com",
"invalid-email",
"test@mailinator.com",
"user@gnail.com",
"user@gmail.cmo",
"user@nonexistentdomain.xyz"
]
for email in emails:
result = validator.validate(email)
if result["valid"]:
print(f"{email} is valid!")
else:
print(f"Error with {email}: {result['error']}")
To run the tests, use the following command:
python -m unittest discover
This project is licensed under the MIT License. See the LICENSE file for details.
Contributions are welcome! Feel free to contribute to this project if you want to add new features, improve existing ones, or fix bugs.
Please raise and issue for bug reporst, feature requests or suggestions.
Chukwuka Ibejih
For any questions or feedback, please contact chukaibejih@gmail.com.
This library uses the following third-party packages:
Django for email validation
Levenshtein for string similarity calculations
dnspython for DNS queries
If you love this project, please consider giving me 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.