This is a script that takes a CSV file containing email addresses from a dirty data source, and splits it into two CSVs, one containing valid email addresses, and the other invalid.
First, clone the alphagov/notifications-utils repository. Add this script to the root, and make it executable:
chmod +x validate-emails.py
Set up a virtual environment and install dependencies:
python3 -mvenv env
source env/bin/activate
pip install -r requirements.txt
Then run on your csv:
./validate-emails.py ./path/to/your.csv
By default, it checks a column named Email
. If your email column has a different name, specify it like this:
./validate-emails.py ./path/to/your.csv --column="email-address"
If the input file is called foo.csv
, valid records will be output into foo_clean.csv
, and invalid records will go into foo_rejected.csv
.