Configure email notifications Stay organized with collections Save and categorize content based on your preferences.
Cloud Composer 3 | Cloud Composer 2 | Cloud Composer 1
This page explains how to configure SMTP services for yourCloud Composer environment.
Before you begin
If your Cloud Composer environment isconfigured for Private IP, make sure that it hasconnectivity to the API endpoint for your external email service (such as
https://api.sendgrid.com, or your preferred SMTP server).
Configure SendGrid email services
To receive notifications, configure your environment variablesto send email through the SendGrid email service.
Sign up with SendGrid
If you haven't already, sign up with SendGrid in Google Cloud console, clickManage On Provider to go to the SendGrid domain, and click Settings to retrieveyour username and to create an API key. As a Google Cloud developer, you canstart with 12,000 free emails per month.
Configure variables
SendGrid uses the API key and a From email address for sending mail. Youcan provide this information with one of the following options:
(Recommended)Store values in Secret Manager
Note: This option is available in Airflow 2.1.4 and later versions. InAirflow versions from 2.1.4 to 2.2.3, you still need to use an environmentvariable to set the email address, but you can store the SendGrid API key ina secret.- Caution: If you use this option, the value for the SendGrid API key isstored in an Airflow connection.
Store values in Secret Manager
To store values in Secret Manager:
Configure Secret Manager for yourenvironment. Make sure to set up permissions and Airflow configurationoptions for the secrets backend.
Override the following Airflow configuration options:
Section Key Value emailemail_conn_idsendgrid_defaultemailemail_backendairflow.providers.sendgrid.utils.emailer.send_emailCreate a secret for the SendGrid connection named
airflow-connections-sendgrid_default. Set the secret's value to theconnection URI. For example:sendgrid://<username>:<sendgrid_api_key>@smtp.sendgrid.net:587For more information about storing connections inSecret Manager, seeManage Airflow connections.
Configure the email address for SendGrid. It's not possible to set up theemail address through a secret. Instead,override thefollowing Airflow configuration option:
Deprecated: In Airflow versions 2.1.4 to 2.1.3,set theSection Key Value emailfrom_emailThe From email address, such as noreply@example.com.SENDGRID_MAIL_FROMenvironment variable instead ofoverriding the Airflow configuration option.
Store values in Airflow
Override the following Airflow configuration options:
Section Key Value emailemail_conn_idsendgrid_defaultemailemail_backendairflow.providers.sendgrid.utils.emailer.send_emailIn Airflow,configure the connectionnamed
sendgrid_default. Specify the Sendgrid API key in the connectionURI. For example:gcloudcomposerenvironmentsrunENVIRONMENT_NAME\--locationLOCATION\connectionsadd--\--conn-uri"sendgrid://USERNAME:SENDGRID_API_KEY@smtp.sendgrid.net:587"\sendgrid_defaultReplace the following:
ENVIRONMENT_NAME: the name of your environment.LOCATION: the region where the environment is located.USERNAME: the SendGrid username.SENDGRID_API_KEY: the SendGrid API key.
Configure the email address for SendGrid. It's not possible to set up theemail address through a secret. Instead,override thefollowing Airflow configuration option:
Deprecated: In Airflow versions 2.1.4 to 2.1.3,set theSection Key Value emailfrom_emailThe From email address, such as noreply@example.com.SENDGRID_MAIL_FROMenvironment variable instead ofoverriding the Airflow configuration option.
Test your SendGrid configuration
To test SendGrid configuration:
- Create a test DAG that uses the
EmailOperator. For example:
importdatetimeimportairflowfromairflow.operators.emailimportEmailOperatorwithairflow.DAG("composer_sample_sendgrid",start_date=datetime.datetime(2022,1,1),)asdag:task_email=EmailOperator(task_id="send-email",conn_id="sendgrid_default",# You can specify more than one recipient with a list.to="user@example.com",subject="EmailOperator test for SendGrid",html_content="This is a test message sent through SendGrid.",dag=dag,)- Upload the DAG to your environment and check that the task succeeds.
- Sign in to SendGrid in with your SendGrid credentials.
- In the SendGrid UI, go to Activity page.
- Search the list for the email. You should see that SendGrid processed and delivered the email.
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 theemail_backend Airflow configuration optionand configure other SMTP-related parameters.
smtp_password because the value is stored in plain text inairflow.cfgand considered non-secure. SeeConfiguring an SMTP passwordto learn about setting an SMTP password in a more secure way.To configure a third-party SMTP service,override the following Airflow configuration options:
| Section | Key | Value |
|---|---|---|
email | email_backend | airflow.utils.email.send_email_smtp |
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 viasmtp_password is not supported. To set an SMTP password, follow instructions provided inConfiguring an SMTP password. |
smtp | smtp_mail_from | The From email address, such asnoreply-composer@. |
smtp | smtp_starttls | For enhanced security, set toTrue. |
smtp | smtp_ssl | For enhanced security, set toTrue. |
Configure an SMTP password for a third-party SMTP service
Keeping an SMTP password in plain text in Airflow configuration file is a badsecurity practice. That's why Cloud Composer does not supportthis method. Instead, you can use two other methods for configuring an SMTPpassword.
Using a command to retrieve the SMTP password
It is not possible to retrieve the SMTP password using a command inCloud Composer 1. Providing password through a command will trigger anerror when accessingAdmin>Configuration in theAirflow UI.
Using a secret stored in Secret Manager to retrieve an SMTP password
You canconfigure Secret Manager as yourAirflow secrets backend.
Note: If thesmtp_ssl Airflow configuration option is set toTrue for yourenvironment, then disable this override if you get theSSL_WRONG_VERSION_NUMBER error.Once you configure Secret Manager for your Composerenvironment, you can store an SMTP password in Secret Manager:
Create a new secret:
echo-n"SMTP_PASSWORD"|gcloudbetasecretscreate\airflow-config-smtp-password\--data-file=-\--replication-policy=automaticReplace
SMTP_PASSWORDwith your SMTP password.Configure Airflow to obtain the SMTP password fromSecret Manager. To do so,overridethe following Airflow configuration option:
Section Key Value smtpsmtp_password_secretsmtp-password
What's next
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-12-15 UTC.