Email Configuration

You can configure the email that is being sent in your airflow.cfg by setting a subject_template and/or a html_content_template in the email section.

[email]

email_backend = airflow.utils.email.send_email_smtp

subject_template = /path/to/my_subject_template_file
html_content_template = /path/to/my_html_content_template_file

If you want to check which email backend is currently set, you can use airflow config get-value email email_backend command as in the example below.

$ airflow config get-value email email_backend
airflow.utils.email.send_email_smtp

To access the task’s information you use Jinja Templating in your template files.

For example a html_content_template file could look like this:

Try {{try_number}} out of {{max_tries + 1}}<br>
Exception:<br>{{exception_html}}<br>
Log: <a href="{{ti.log_url}}">Link</a><br>
Host: {{ti.hostname}}<br>
Log file: {{ti.log_filepath}}<br>
Mark success: <a href="{{ti.mark_success_url}}">Link</a><br>

Note

For more information on setting the configuration, see Setting Configuration Options

Send email using SendGrid

Airflow can be configured to send e-mail using SendGrid.

Follow the steps below to enable it:

  1. Include sendgrid subpackage as part of your Airflow installation, e.g.,

pip install 'apache-airflow[sendgrid]'
  1. Update email_backend property in [email] section in airflow.cfg, i.e.

    [email]
    email_backend = airflow.providers.sendgrid.utils.emailer.send_email
    
  2. Configure SendGrid specific environment variables at all Airflow instances:

    export SENDGRID_MAIL_FROM={your-mail-from}
    export SENDGRID_API_KEY={your-sendgrid-api-key}