Skip to content

Airflow hook and operator for email validation on Mailgun ✉️🔫

License

Notifications You must be signed in to change notification settings

airflow-plugins/mailgun_plugin

Repository files navigation

Airflow Mailgun Plugin

Maintainability

Test Coverage

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.

Setup

In the root of your Airflow project run:

$ pip install -U git+https://github.com/airflow-plugins/mailgun_plugin.git@v0.0.1

Quickstart

  1. Create an S3 bucket my_bucket on AWS or use an existing one.
  2. 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>"}
  1. Create an S3 connection in Airflow:
- Conn Id: aws_s3
- Conn type: S3
- Login: <AWS Access Key ID>
- Password: <AWS Secret Access Key>
  1. Create a Mailgun connection in Airflow:
- Conn Id: mailgun_api
- Conn type: (empty)
- Login: <Mailgun Public Validation Key>
  1. 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,
)

Notes

Mailgun Email Validation Pricing

Your first 100 email validations per month are free; beyond that, see the Mailgun Pricing page.

Test

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

Development

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