Am 15. September 2026erreichen alle Cloud Composer 1- und Cloud Composer 2-Umgebungen der Version 2.0.x das geplante Ende des Lebenszyklus und können nicht mehr verwendet werden. Wir empfehlen, die Migration zu Cloud Composer 3 zu planen.
Auf dieser Seite wird erläutert, wie Sie SMTP-Dienste für Ihre Cloud Composer-Umgebung konfigurieren.
Hinweise
Wenn Ihre Cloud Composer-Umgebung für private IP-Adressen konfiguriert ist, prüfen Sie, ob sie eine Verbindung zum API-Endpunkt für Ihren externen E-Mail-Dienst hat (z. B. https://api.sendgrid.com oder Ihren bevorzugten SMTP-Server).
SendGrid-E-Mail-Dienste konfigurieren
Damit Sie Benachrichtigungen erhalten, konfigurieren Sie Ihre Umgebungsvariablen so, dass E-Mails über den SendGrid-E-Mail-Dienst gesendet werden.
Bei SendGrid registrieren
Wenn Sie sich noch nicht bei SendGrid in der Google Cloud Console angemeldet haben, klicken Sie auf „Beim Anbieter verwalten“, um zur SendGrid-Domain zu gelangen, und klicken Sie auf „Einstellungen“, um Ihren Nutzernamen abzurufen und einen API-Schlüssel zu erstellen. Als Google Cloud -Entwickler können Sie mit 12.000 kostenlosen E-Mails pro Monat beginnen.
SendGrid verwendet den API-Schlüssel und eine „Von“-E-Mail-Adresse zum Senden von E-Mails. Sie können diese Informationen auf eine der folgenden Arten angeben:
Erstellen Sie ein Secret für die SendGrid-Verbindung mit dem Namen airflow-connections-sendgrid_default. Legen Sie den Wert des Secrets auf den Verbindungs-URI fest. Beispiel:
Konfigurieren Sie die E-Mail-Adresse für SendGrid. Es ist nicht möglich, die E‑Mail-Adresse über ein Secret einzurichten. Überschreiben Sie stattdessen die folgende Airflow-Konfigurationsoption:
Bereich
Schlüssel
Wert
email
from_email
Die E-Mail-Adresse des Absenders, z. B. noreply@example.com.
In Airflow-Versionen 2.1.4 bis 2.1.3 legen Sie die SENDGRID_MAIL_FROMUmgebungsvariable fest, anstatt die Airflow-Konfigurationsoption zu überschreiben.
Werte in Airflow speichern
Überschreiben Sie die folgenden Airflow-Konfigurationsoptionen:
LOCATION: die Region, in der sich die Umgebung befindet.
USERNAME: der SendGrid-Nutzername.
SENDGRID_API_KEY: der SendGrid API-Schlüssel.
Konfigurieren Sie die E-Mail-Adresse für SendGrid. Es ist nicht möglich, die E‑Mail-Adresse über ein Secret einzurichten. Überschreiben Sie stattdessen die folgende Airflow-Konfigurationsoption:
Bereich
Schlüssel
Wert
email
from_email
Die E-Mail-Adresse des Absenders, z. B. noreply@example.com.
In Airflow-Versionen 2.1.4 bis 2.1.3 legen Sie die SENDGRID_MAIL_FROMUmgebungsvariable fest, anstatt die Airflow-Konfigurationsoption zu überschreiben.
SendGrid-Konfiguration testen
So testen Sie die SendGrid-Konfiguration:
Erstellen Sie einen Test-DAG, der EmailOperator verwendet. Beispiel:
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,)
Melden Sie sich bei SendGrid mit Ihren SendGrid-Anmeldedaten an.
Wechseln Sie in der SendGrid-Benutzeroberfläche zur Seite "Aktivität".
Durchsuchen Sie die Liste nach der E-Mail. Es sollte nun sichtbar sein, dass SendGrid die E-Mail verarbeitet und zugestellt hat.
Falls die E-Mail nicht verarbeitet und zugestellt wurde:
Überprüfen Sie die SendGrid-Konfiguration.
Prüfen Sie, ob Sie das Secret Manager-Backend aktiviert haben. Achten Sie darauf, dass Sie zusätzliche Berechtigungen erteilt und Überschreibungen für Airflow-Konfigurationsoptionen festgelegt haben.
Überprüfen Sie den Spamfilter in Ihrem E-Mail-Client.
SMTP-Dienste von Drittanbietern konfigurieren
Zum Senden von E-Mails über den SMTP-Dienst eines Drittanbieters überschreiben Sie die Airflow-Konfigurationsoption email_backend und konfigurieren Sie weitere SMTP-bezogene Parameter.
Zum Konfigurieren eines SMTP-Dienstes eines Drittanbieters überschreiben Sie die folgenden Airflow-Konfigurationsoptionen:
Bereich
Schlüssel
Wert
email
email_backend
airflow.utils.email.send_email_smtp
smtp
smtp_host
Der Hostname für den SMTP-Server.
smtp
smtp_user
Der Nutzername auf dem SMTP-Server.
smtp
smtp_port
Der Port für den SMTP-Server. Port 25 ist nicht verfügbar. Sie können auch andere Ports verwenden, z. B. die SMTP-Standardports 465 und 587.
smtp
smtp_password
Das Festlegen eines Passworts über smtp_password wird nicht unterstützt. Folgen Sie der Anleitung unter SMTP-Passwort konfigurieren, um ein SMTP-Passwort festzulegen.
smtp
smtp_mail_from
Die E-Mail-Adresse des Absenders, z. B. noreply-composer@.
smtp
smtp_starttls
Attribut zur Erhöhung der Sicherheit mit True.
smtp
smtp_ssl
Attribut zur Erhöhung der Sicherheit mit True.
SMTP-Passwort für den SMTP-Dienst eines Drittanbieters konfigurieren
Die Beibehaltung eines SMTP-Passworts als Klartext in der Airflow-Konfigurationsdatei ist nicht empfehlenswert. Deshalb unterstützt Cloud Composer diese Methode nicht. Stattdessen können Sie ein SMTP-Passwort mit zwei anderen Methoden konfigurieren.
SMTP-Passwort mit einem Befehl abrufen
Sie können eine Konfigurationsüberschreibung verwenden, um einen Befehl anzugeben, der das SMTP-Passwort abruft. Bei der Kommunikation mit Ihrem SMTP-Dienst verwendet Airflow diesen Befehl, um den Wert des Passworts abzurufen. Geben Sie einen einzelnen Befehl ohne Bash-Operatoren wie Pipes und Weiterleitungen an.
Um diese Methode zu verwenden, überschreiben Sie die folgende Airflow-Konfigurationsoption:
Bereich
Schlüssel
Wert
smtp
smtp_password_cmd
Geben Sie einen Befehl an, der das SMTP-Passwort zurückgibt.
SMTP-Passwort mit einem in Secret Manager gespeicherten Secret abrufen
Ersetzen Sie SMTP_PASSWORD durch Ihr SMTP-Passwort.
Konfigurieren Sie Airflow so, dass das SMTP-Passwort vom Secret Manager abgerufen wird. Überschreiben Sie dazu die folgende Airflow-Konfigurationsoption:
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Schwer verständlich","hardToUnderstand","thumb-down"],["Informationen oder Beispielcode falsch","incorrectInformationOrSampleCode","thumb-down"],["Benötigte Informationen/Beispiele nicht gefunden","missingTheInformationSamplesINeed","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Sonstiges","otherDown","thumb-down"]],["Zuletzt aktualisiert: 2025-08-26 (UTC)."],[[["\u003cp\u003eThis guide provides instructions on configuring SMTP services for Cloud Composer environments, detailing how to set up email notifications.\u003c/p\u003e\n"],["\u003cp\u003eSendGrid is the recommended email service, and users can sign up via the Google Cloud console and use the SendGrid API key to send emails.\u003c/p\u003e\n"],["\u003cp\u003eThere are two ways to store the SendGrid API key and connection details: in Secret Manager (recommended, available from Airflow 2.1.4) or directly in Airflow, in which the latter is not as secure.\u003c/p\u003e\n"],["\u003cp\u003eUsers can also configure third-party SMTP services, but directly storing the SMTP password in the Airflow configuration is discouraged for security reasons.\u003c/p\u003e\n"],["\u003cp\u003eFor enhanced security when using third party SMTP, the password should be managed by retrieving it via a command or storing it in Secret Manager, which is the recommended way.\u003c/p\u003e\n"]]],[],null,["# Configure email notifications\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\n[Cloud Composer 3](/composer/docs/composer-3/configure-email \"View this page for Cloud Composer 3\") \\| **Cloud Composer 2** \\| [Cloud Composer 1](/composer/docs/composer-1/configure-email \"View this page for Cloud Composer 1\")\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nThis page explains how to configure SMTP services for your\nCloud Composer environment.\n\nBefore you begin\n----------------\n\n- If your Cloud Composer environment is\n [configured for Private IP](/composer/docs/composer-2/configure-private-ip), make sure that it has\n connectivity to the API endpoint for your external email service (such as\n `https://api.sendgrid.com`, or your preferred SMTP server).\n\nConfigure SendGrid email services\n---------------------------------\n\nTo receive notifications, configure your environment variables\nto send email through the SendGrid email service.\n\n### Sign up with SendGrid\n\nIf you haven't already, sign up with SendGrid in Google Cloud console, click\nManage On Provider to go to the SendGrid domain, and click Settings to retrieve\nyour username and to create an API key. As a Google Cloud developer, you can\nstart with 12,000 free emails per month.\n\n[Go to SendGrid Email API](https://console.cloud.google.com/marketplace/details/sendgrid-app/sendgrid-email)\n\n### Configure variables\n\nSendGrid uses the API key and a From email address for sending mail. You\ncan provide this information with one of the following options:\n\n- (Recommended)\n [Store values in Secret Manager](#store-secret-manager)\n\n | **Note:** This option is available in Airflow 2.1.4 and later versions. In Airflow versions from 2.1.4 to 2.2.3, you still need to use an environment variable to set the email address, but you can store the SendGrid API key in a secret.\n- [Store values in Airflow](#store-airflow)\n\n | **Caution:** If you use this option, the value for the SendGrid API key is stored in an Airflow connection.\n\n#### Store values in Secret Manager\n\nTo store values in Secret Manager:\n\n1. [Configure Secret Manager](/composer/docs/composer-2/configure-secret-manager) for your\n environment. Make sure to set up permissions and Airflow configuration\n options for the secrets backend.\n\n2. [Override](/composer/docs/composer-2/override-airflow-configurations) the following Airflow configuration options:\n\n3. Create a secret for the SendGrid connection named\n `airflow-connections-sendgrid_default`. Set the secret's value to the\n connection URI. For example:\n\n sendgrid://\u003cusername\u003e:\u003csendgrid_api_key\u003e@smtp.sendgrid.net:587\n\n For more information about storing connections in\n Secret Manager, see\n [Manage Airflow connections](/composer/docs/composer-2/manage-airflow-connections).\n4. Configure the email address for SendGrid. It's not possible to set up the\n email address through a secret. Instead, [override](/composer/docs/composer-2/override-airflow-configurations) the\n following Airflow configuration option:\n\n | **Deprecated:** In Airflow versions 2.1.4 to 2.1.3, set the `SENDGRID_MAIL_FROM` [environment variable](/composer/docs/composer-2/set-environment-variables) instead of overriding the Airflow configuration option.\n\n#### Store values in Airflow\n\n1. [Override](/composer/docs/composer-2/override-airflow-configurations) the following Airflow configuration options:\n\n2. In Airflow, [configure the connection](/composer/docs/composer-2/manage-airflow-connections)\n named `sendgrid_default`. Specify the Sendgrid API key in the connection\n URI. For example:\n\n gcloud composer environments run \u003cvar translate=\"no\"\u003eENVIRONMENT_NAME\u003c/var\u003e \\\n --location \u003cvar translate=\"no\"\u003eLOCATION\u003c/var\u003e \\\n connections add -- \\\n --conn-uri \"sendgrid://\u003cvar translate=\"no\"\u003eUSERNAME\u003c/var\u003e:\u003cvar translate=\"no\"\u003eSENDGRID_API_KEY\u003c/var\u003e@smtp.sendgrid.net:587\" \\\n sendgrid_default\n\n Replace the following:\n - `ENVIRONMENT_NAME`: the name of your environment.\n - `LOCATION`: the region where the environment is located.\n - `USERNAME`: the SendGrid username.\n - `SENDGRID_API_KEY`: the SendGrid API key.\n3. Configure the email address for SendGrid. It's not possible to set up the\n email address through a secret. Instead, [override](/composer/docs/composer-2/override-airflow-configurations) the\n following Airflow configuration option:\n\n | **Deprecated:** In Airflow versions 2.1.4 to 2.1.3, set the `SENDGRID_MAIL_FROM` [environment variable](/composer/docs/composer-2/set-environment-variables) instead of overriding the Airflow configuration option.\n\n### Test your SendGrid configuration\n\nTo test SendGrid configuration:\n\n1. Create a test DAG that uses the `EmailOperator`. For example:\n\n\n import datetime\n\n import airflow\n from airflow.operators.email import EmailOperator\n\n\n with airflow.DAG(\n \"composer_sample_sendgrid\",\n start_date=datetime.datetime(2022, 1, 1),\n ) as dag:\n task_email = EmailOperator(\n task_id=\"send-email\",\n conn_id=\"sendgrid_default\",\n # You can specify more than one recipient with a list.\n to=\"user@example.com\",\n subject=\"EmailOperator test for SendGrid\",\n html_content=\"This is a test message sent through SendGrid.\",\n dag=dag,\n )\n\n1. [Upload the DAG](/composer/docs/composer-2/manage-dags#add) to your environment and check that the task succeeds.\n2. Sign in to SendGrid in with your SendGrid credentials.\n3. In the SendGrid UI, go to Activity page.\n4. Search the list for the email. You should see that SendGrid processed and delivered the email.\n5. If the email is not processed and delivered:\n\n - Check your SendGrid configuration.\n - Verify that you enabled the Secret Manager backend. Make sure that you granted extra permissions and set overrides for Airflow configuration options.\n - Check the spam filter in your email client.\n\nConfigure third-party SMTP services\n-----------------------------------\n\nTo send email through a third-party SMTP service,\n[override](/composer/docs/composer-2/override-airflow-configurations) the `email_backend` Airflow configuration option\nand configure other SMTP-related parameters.\n| **Note:** Using a third-party SMTP service requires setting an SMTP password. Cloud Composer does not support configuring the `smtp_password` because the value is stored in plain text in `airflow.cfg` and considered non-secure. See [Configuring an SMTP password](#smtp_password) to learn about setting an SMTP password in a more secure way.\n\nTo configure a third-party SMTP service, [override](/composer/docs/composer-2/override-airflow-configurations) the following Airflow configuration options:\n\n### Configure an SMTP password for a third-party SMTP service\n\nKeeping an SMTP password in plain text in Airflow configuration file is a bad\nsecurity practice. That's why Cloud Composer does not support\nthis method. Instead, you can use two other methods for configuring an SMTP\npassword.\n\n#### Using a command to retrieve the SMTP password\n\nYou can use a configuration override to specify a command that obtains the\nSMTP password. When communicating with your SMTP service, Airflow uses this\ncommand to get the value of the password. Specify a single command, without\nbash operators such as pipes and redirects.\n\nTo use this method, [override](/composer/docs/composer-2/override-airflow-configurations) the following Airflow\nconfiguration option:\n\n\n#### Using a secret stored in Secret Manager to retrieve an SMTP password\n\nYou can [configure Secret Manager](/composer/docs/composer-2/configure-secret-manager) as your\nAirflow secrets backend.\n| **Note:** If the `smtp_ssl` Airflow configuration option is set to `True` for your environment, then disable this override if you get the `SSL_WRONG_VERSION_NUMBER` error.\n\nOnce you configure Secret Manager for your Composer\nenvironment, you can store an SMTP password in Secret Manager:\n\n1. Create a new secret:\n\n echo -n \"\u003cvar translate=\"no\"\u003eSMTP_PASSWORD\u003c/var\u003e\" | gcloud beta secrets create \\\n airflow-config-smtp-password \\\n --data-file=- \\\n --replication-policy=automatic\n\n Replace `SMTP_PASSWORD` with your SMTP password.\n2. Configure Airflow to obtain the SMTP password from\n Secret Manager. To do so, [override](/composer/docs/composer-2/override-airflow-configurations)\n the following Airflow configuration option:\n\nWhat's next\n-----------\n\n- [Override Airflow configuration options](/composer/docs/composer-2/override-airflow-configurations)\n- [Set environment variables](/composer/docs/composer-2/set-environment-variables)"]]