How to set up Airflow Send Email?

Setting up SMTP Server for Airflow Email alerts using Gmail:

Create an email id from which you want to send alerts about DAG failure or if you want to use EmailOperator. Edit airflow.cfg file to edit the smtp details for the mail server.

For demo you can use any gmail account.

Create a google App Password for your gmail account (Instruction here). This is done so that you don’t use your original password or 2 Factor authentication.

  1. Visit your App passwords page. You may be asked to sign in to your Google Account.
  2. Under “Your app passwords”, click Select app and choose “Mail”.
  3. Click Select device and choose “Other (Custom name)” so that you can input “Airflow”.
  4. Select Generate.
  5. Copy the generated App password (the 16 character code in the yellow bar), for example xxxxyyyyxxxxyyyy.
  6. Select Done.

Once you are finished, you won’t see that App password code again. However, you will see a list of apps and devices (which you’ve created App passwords for) in your Google Account.

Edit airflow.cfg and edit the [smtp] section as shown below:

[smtp]
smtp_host = smtp.gmail.com
smtp_starttls = True
smtp_ssl = False
smtp_user = YOUR_EMAIL_ADDRESS
smtp_password = xxxxyyyyxxxxyyyy
smtp_port = 587
smtp_mail_from = YOUR_EMAIL_ADDRESS

Edit the below parameters to the corresponding values:

YOUR_EMAIL_ADDRESS = Your Gmail address
xxxxyyyyxxxxyyyy = The App password generated above

Leave a Comment