|
| 1 | +# Copyright 2022 Google LLC |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | + |
| 16 | +"""Example Airflow DAG that sends an email message through SendGrid. |
| 17 | +
|
| 18 | +You must configure email notifications so that Airflow sends email through |
| 19 | +SendGrid. For more information, see |
| 20 | +https://cloud.google.com/composer/docs/composer-2/configure-email#sendgrid |
| 21 | +
|
| 22 | +""" |
| 23 | + |
| 24 | +# [START composer_email_operator_sendgrid] |
| 25 | + |
| 26 | +import datetime |
| 27 | + |
| 28 | +import airflow |
| 29 | +from airflow.operators.email import EmailOperator |
| 30 | + |
| 31 | + |
| 32 | +with airflow.DAG( |
| 33 | + "composer_sample_sendgrid", |
| 34 | + start_date=datetime.datetime(2022, 1, 1), |
| 35 | +) as dag: |
| 36 | + |
| 37 | + task_email = EmailOperator( |
| 38 | + task_id="send-email", |
| 39 | + conn_id="sendgrid_default", |
| 40 | + # You can specify more than one recipient with a list. |
| 41 | + |
| 42 | + subject="EmailOperator test for SendGrid", |
| 43 | + html_content="This is a test message sent through SendGrid.", |
| 44 | + dag=dag, |
| 45 | + ) |
| 46 | + |
| 47 | +# [END composer_email_operator_sendgrid] |
0 commit comments