An Airflow hook and operator to validate a list of emails using the Mailgun Email Validation API.
An example Mailgun validation DAG is available as well.
In the root of your Airflow project run:
$ pip install -U git+https://github.com/airflow-plugins/mailgun_plugin.git@v0.0.1
- Create an S3 bucket
my_bucket
on AWS or use an existing one. - Upload a list of contacts
contacts.json
to it which consists of newline-delimited JSON (ndjson):
{"id": 123, "email": "foo@example.com"}
{"id": 456, "email": "bar@example.com"}
{"id": 96, "email": "info@example.com"}
{"id": 433, "email": "Real Person <rperson@example.com>"}
- Create an S3 connection in Airflow:
- Conn Id: aws_s3 - Conn type: S3 - Login: <AWS Access Key ID> - Password: <AWS Secret Access Key>
- Create a Mailgun connection in Airflow:
- Conn Id: mailgun_api - Conn type: (empty) - Login: <Mailgun Public Validation Key>
- Add a task to your DAG like:
dag = DAG(...)
email_validator = EmailValidationOperator(
task_id='email_validator',
mailgun_conn_id='mailgun_api',
aws_conn_id='aws_s3',
s3_bucket_name='my_bucket',
s3_key_source='contacts.json',
dag=dag,
)
Your first 100 email validations per month are free; beyond that, see the Mailgun Pricing page.
Install:
$ git clone https://github.com/airflow-plugins/mailgun_plugin
$ cd mailgun_plugin
$ pip install -U -r requirements_test.txt
Run tests:
$ pytest
Run coverage:
$ pytest --cov=mailgun_plugin
To show uncovered lines:
$ coverage report --include=mailgun_plugin/* --show-missing
Switch to the root of your Airflow project.
To install:
$ git clone https://github.com/airflow-plugins/mailgun_plugin plugins/mailgun_plugin
$ pip install -U -r plugins/mailgun_plugin/requirements_dev.txt