close

How to set up Airflow Send Email?

Hello Guys, How are you all? Hope You all Are Fine. Today We Are Going To learn about How to set up Airflow Send Email in Python. So Here I am Explain to you all the possible Methods here.

Without wasting your time, Let’s start This Article.

Table of Contents

How to set up Airflow Send Email?

  1. How to set up Airflow Send Email?

    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.

  2. set up Airflow Send Email

    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.

Method 1

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. At the bottom, click Select app and choose the app you’re using.
  3. Click Select device and choose the device you’re using.
  4. Select Generate.
  5. Follow the instructions to enter the App password (the 16 character code in the yellow bar) on your device.
  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 you’ve created App passwords for.

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 = 16_DIGIT_APP_PASSWORD
smtp_port = 587
smtp_mail_from = YOUR_EMAIL_ADDRESS

Edit the below parameters to the corresponding values:

YOUR_EMAIL_ADDRESS = Your Gmail address
16_DIGIT_APP_PASSWORD = The App password generated above

Method 2


I had same issue and i solved it by making sure i am doing a volume mount in my compose file

volumes:
  - ./dags:/usr/local/airflow/dags
  - ./config/airflow.cfg:/usr/local/airflow/airflow.cfg

Summery

It’s all About this issue. Hope all Methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which Method worked for you? Thank You.

Also, Read