This Python script validates email addresses in a mailing list CSV by checking their syntax, domain status, MX records, and whether they belong to known disposable email providers or blacklisted domains. It uses external blocklists for disposable and malicious domains.
- Validates email syntax using regex
- Checks if the domain has valid DNS A records
- Checks if the domain has MX records
- Detects known disposable email domains
- Detects role-based email addresses
- Checks if the domain is blacklisted using an external malicious blocklist
- Python 3.x
requests
modulednspython
module
-
Install Homebrew (if you don't have it already):
Homebrew is a package manager for macOS that makes it easy to install software.
/bin/bash -c "$(curl -fsSL https://github.com/raw/Homebrew/install/HEAD/install.sh)"
-
Install Python (if you don't have it already):
Homebrew can be used to install Python.
brew install python
-
Install
pip
(Python package manager) if it isn't installed:You can install
pip
using Homebrew as well.brew install pip
-
Create a virtual environment (optional but recommended):
A virtual environment isolates your Python dependencies for this project.
python3 -m venv email-validator-env source email-validator-env/bin/activate
-
Install the required Python packages:
Install the
requests
anddnspython
modules usingpip
.pip install requests dnspython
-
Clone the repository:
git clone https://github.com/jameshobden/email-validator.git cd email-validator
-
Place your input CSV file (
input_emails.csv
) in the same directory. The CSV file should have columnsemail
andstatus
. -
Run the script:
python script.py
-
The script will generate an
blacklisted_emails.csv
file containing the emails that failed validation.
is_valid_email_syntax(email)
: Validates email syntax using regex.load_blocklist(file_path)
: Loads blocklist from a specified file.is_blacklisted_domain(email, blocklist)
: Checks if the email domain is blacklisted.is_disposable_email(email, disposable_domains)
: Checks if the email domain is from a known disposable email provider.is_role_based_email(email)
: Checks if the email is a role-based email address.has_valid_domain(email)
: Checks if the domain has valid DNS A records with caching and rate limiting.has_mx_record(email)
: Checks if the domain has MX records with caching and rate limiting.download_file(url, output_file)
: Downloads a file from a URL if it doesn't exist.validate_emails(input_csv, output_csv, disposable_file, malicious_file)
: Reads emails from CSV, validates them, and updates the input CSV.
- Disposable email domains list: disposable_email_blocklist.conf
- Malicious domains blocklist: ultimate.txt
The script automatically downloads these lists if they are not present in the directory.
Feel free!
- Fork the repository
- Create your feature branch (
git checkout -b feature/fooBar
) - Commit your changes (
git commit -am 'Add some fooBar'
) - Push to the branch (
git push origin feature/fooBar
) - Create a new Pull Request