Airflow Summit 2023
Join the Airflow community on September 19—21 during the Airflow Summit 2023 conference to learn more about Airflow and share your expertise. Call for papers is now open

Configure email notifications

Stay organized with collections Save and categorize content based on your preferences.

Cloud Composer 1 | Cloud Composer 2

This page explains how to configure SMTP services for your Cloud Composer environment.

Before you begin

If your Cloud Composer environment is configured for Private IP, make sure that it has connectivity to the API endpoint for your external email service (such as, or your preferred SMTP server).

Configure SendGrid email services

To receive notifications, configure your environment variables to send email through the SendGrid email service.

Sign up with SendGrid

If you haven't already, sign up with SendGrid in Google Cloud console, click Manage On Provider to go to the SendGrid domain, and click Settings to retrieve your username and to create an API key. As a Google Cloud developer, you can start with 12,000 free emails per month.

Go to SendGrid Email API

Configure variables

SendGrid uses the API key and a From email address for sending mail. You can provide this information with one of the following options:

  • (Recommended) Store values in Secret Manager.

  • Set the values using environment variables.

Store values in Secret Manager

To store values in Secret Manager:

  1. Install the apache-airflow-providers-sendgrid PyPI package.

  2. Configure Secret Manager for your environment. Make sure to set up permissions and Airflow configuration options for the secrets backend.

  3. Override the following Airflow configuration options:

    Section Key Value
    email email_conn_id sendgrid_default
    email email_backend airflow.providers.sendgrid.utils.emailer.send_email
  4. Create a secret for the SendGrid connection named airflow-connections-sendgrid_default. Set the secret's value to the connection URI. For example:

  5. Configure the email address for SendGrid:

    • (Airflow 2.2.4 and later versions) Create a secret named airflow-variables-from_email. Set the secret's value to the From email address, such as
    • (Airflow versions 2.1.4 to 2.1.3) Set the following environment variable for your environment:

      Name Value
      SENDGRID_MAIL_FROM The From email address, such as

Store values in environment variables

To store values in environment variables:

  1. Set the following environment variables for your environment:

    Name Value
    SENDGRID_MAIL_FROM The From email address, such as
    SENDGRID_API_KEY Your SendGrid API key.

Test your SendGrid configuration

To test SendGrid configuration:

  1. Create a test DAG that uses the EmailOperator. For example:

import datetime

import airflow
from import EmailOperator

with airflow.DAG(
    start_date=datetime.datetime(2022, 1, 1),
) as dag:

    task_email = EmailOperator(
        # You can specify more than one recipient with a list.
        subject="EmailOperator test for SendGrid",
        html_content="This is a test message sent through SendGrid.",
  1. Upload the DAG to your environment and check that the task succeeds.
  2. Sign in to SendGrid in with your SendGrid credentials.
  3. In the SendGrid UI, go to Activity page.
  4. Search the list for the email. You should see that SendGrid processed and delivered the email.
  5. If the email is not processed and delivered:

    • Check your SendGrid configuration.
    • Verify that you enabled the Secret Manager backend. Make sure that you granted extra permissions and set overrides for Airflow configuration options.
    • Check the spam filter in your email client.

Configure third-party SMTP services

To send email through a third-party SMTP service, override the email_backend Airflow configuration option and configure other SMTP-related parameters.

To configure a third-party SMTP service, override the following Airflow configuration options:

Section Key Value
email email_backend
smtp smtp_host The hostname for the SMTP server.
smtp smtp_user The username on the SMTP server.
smtp smtp_port The port for the SMTP server. Port 25 is not available. You can use other ports, such as standard SMTP ports 465 and 587.
smtp smtp_password Setting a password via smtp_password is not supported. To set an SMTP password, follow instructions provided in Configuring an SMTP password.
smtp smtp_mail_from The From email address, such as noreply-composer@.
smtp smtp_starttls For enhanced security, set to True.
smtp smtp_ssl For enhanced security, set to True.

Configure an SMTP password for a third-party SMTP service

Keeping an SMTP password in plain text in Airflow configuration file is a bad security practice. That's why Cloud Composer does not support this method. Instead, you can use two other methods for configuring an SMTP password.

Using a command to retrieve an SMTP password

You can use a configuration override to specify a command that obtains the SMTP password. When communicating with your SMTP service, Airflow uses this command to get the value of the password. Specify a single command, without bash operators such as pipes and redirects.

To use this method, override the following Airflow configuration option:

Section Key Value
smtp smtp_password_cmd Specify a command that returns the SMTP password.

Using a secret stored in Secret Manager to retrieve an SMTP password

You can configure Secret Manager as your Airflow secrets backend.

Once you configure Secret Manager for your Composer environment, you can store an SMTP password in Secret Manager:

  1. Create a new secret:

    echo -n "SMTP_PASSWORD" | gcloud beta secrets create \
      airflow-config-smtp-password \
      --data-file=- \

    Replace SMTP_PASSWORD with your SMTP password.

  2. Configure Airflow to obtain the SMTP password from Secret Manager. To do so, override the following Airflow configuration option:

    Section Key Value
    smtp smtp_password_secret smtp-password

What's next