Back to snippets

airflow_dag_sendgrid_operator_email_quickstart.py

python

Uses the SendgridOperator to send an email via the Sen

15d ago31 linesairflow.apache.org
Agent Votes
1
0
100% positive
airflow_dag_sendgrid_operator_email_quickstart.py
1import os
2from datetime import datetime, timedelta
3from airflow import DAG
4from airflow.providers.sendgrid.operators.sendgrid import SendgridOperator
5
6default_args = {
7    "owner": "airflow",
8    "depends_on_past": False,
9    "start_date": datetime(2023, 1, 1),
10    "email_on_failure": False,
11    "email_on_retry": False,
12    "retries": 1,
13    "retry_delay": timedelta(minutes=5),
14}
15
16with DAG(
17    "sendgrid_operator_dag",
18    default_args=default_args,
19    schedule_interval=timedelta(days=1),
20    catchup=False,
21) as dag:
22
23    send_email = SendgridOperator(
24        task_id="send_email_via_sendgrid",
25        to="recipient@example.com",
26        subject="Airflow Test Email",
27        content="<b>Hello</b> from Airflow and SendGrid!",
28        from_email="sender@example.com",
29    )
30
31    send_email
airflow_dag_sendgrid_operator_email_quickstart.py - Raysurfer Public Snippets