0
0
Apache Airflowdevops~30 mins

EmailOperator for notifications in Apache Airflow - Mini Project: Build & Apply

Choose your learning style9 modes available
EmailOperator for notifications
📖 Scenario: You are setting up an Airflow workflow to send email notifications when a task completes. This helps your team stay informed about important events automatically.
🎯 Goal: Build a simple Airflow DAG that uses the EmailOperator to send an email notification.
📋 What You'll Learn
Create a DAG with the id email_notification_dag
Use EmailOperator to send an email
Set the email recipient to team@example.com
Set the email subject to Airflow Notification
Set the email body to Task completed successfully.
Schedule the DAG to run once daily
💡 Why This Matters
🌍 Real World
Automating email notifications in workflows helps teams stay updated without manual checks.
💼 Career
Knowing how to use EmailOperator is useful for DevOps engineers and data engineers managing Airflow pipelines.
Progress0 / 4 steps
1
Create the DAG structure
Import DAG from airflow and create a DAG object called email_notification_dag with start_date set to 2024, 1, 1 and schedule_interval set to @daily.
Apache Airflow
Need a hint?

Use DAG constructor with the exact parameters given.

2
Import EmailOperator and set email parameters
Import EmailOperator from airflow.operators.email. Create variables to_email with value 'team@example.com', email_subject with value 'Airflow Notification', and email_body with value 'Task completed successfully.'.
Apache Airflow
Need a hint?

Remember to import EmailOperator and create the three variables exactly as shown.

3
Create the EmailOperator task
Create an EmailOperator task called send_email inside the DAG email_notification_dag. Use the variables to_email, email_subject, and email_body for the to, subject, and html_content parameters respectively.
Apache Airflow
Need a hint?

Create the EmailOperator with the exact parameters and variable names.

4
Print confirmation message
Write a print statement that outputs the text 'EmailOperator task created successfully.'
Apache Airflow
Need a hint?

Use print with the exact message inside quotes.