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.

  1. [email]
  2. email_backend = airflow.utils.email.send_email_smtp
  3. subject_template = /path/to/my_subject_template_file
  4. 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.

  1. $ airflow config get-value email email_backend
  2. 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:

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

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

1. 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.,

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

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

    1. $ export SENDGRID_MAIL_FROM={your-mail-from}
    2. $ export SENDGRID_API_KEY={your-sendgrid-api-key}
  1. Create a connection called sendgrid_default, or choose a custom connection name and set it in email_conn_id.

    2. Send email using AWS SES

    Airflow can be configured to send e-mail using AWS SES.

Follow the steps below to enable it:

  1. Include amazon subpackage as part of your Airflow installation:

    1. $ pip install 'apache-airflow[amazon]'
  2. Update email_backend property in [email] section in airflow.cfg:

    1. [email]
    2. email_backend = airflow.providers.amazon.aws.utils.emailer.send_email
    3. email_conn_id = aws_default
  3. Create a connection called aws_default, or choose a custom connection name and set it in email_conn_id.