首页 > 解决方案 > 如何设置 Airflow 自定义电子邮件模板

问题描述

在 中airflow.cfg,我已经设置了我需要的电子邮件外观,但是当发送电子邮件时,我指定的设置/布局没有被应用。

subject_template = 'Airflow alert: {{ti}}'

# File that will be used as the template for Email content (which will be rendered using Jinja2).
# If not set, Airflow uses a base template.
# Example: html_content_template = /path/to/my_html_content_template_file
html_content_template = (
        'Try {{try_number}} out of {{max_tries + 1}}<br>'
        'Job Name: {{ti.dag_id}}<br>'
        'Task Id: {{ti.task_id}}<br>'
        'Exception: {{exception_html}}<br>'
        'Log: <a href={{ti.log_url}} target="_blank">Link</a><br>'
        'Host: {{ti.hostname}}<br>'
        'Log file: {{ti.log_filename}}<br>')

我错过了什么?

标签: airflow

解决方案


来自html_content_template的文档:

将用作电子邮件内容模板的文件(将使用 Jinja2 呈现)。如果未设置,Airflow 将使用基本模板。

我猜期望值是这样的:

html_content_template = /path/to/my_html_content_template_file

尝试使用模板创建文件并在设置中提供该文件的路径。


推荐阅读