Blueprints

Send an SendGrid email notification when a workflow fails

About this blueprint

Notifications System

This system flow will send an SendGrid email notification anytime a workflow in a company namespace (or any nested child namespace) fails.

Using this pattern, you can send email notifications for Kestra workflow execution failures alongside other notifications.

You can customize that system flow by modifying the task, adding more tasks to the flow or adjusting the trigger conditions. Read more about that pattern in the Administrator Guide.

Let's create a flow in the namespace with prefix company that will always fail.

yaml
id: failure_flow
namespace: company.team

tasks:
  - id: always_fails
    type: io.kestra.plugin.core.execution.Fail

Whenever you run the failure_flow, it will trigger an execution of the sengrid_notify_on_failure flow. As a result, an email notification will be created using SendGrid so that prompt action can be taken.

yaml
id: sengrid_notify_on_failure
namespace: company.team

tasks:
  - id: send_email_notification
    type: io.kestra.plugin.notifications.sendgrid.SendGridMailExecution
    to:
      - hello@kestra.io
    from: hello@kestra.io
    subject: "Kestra Workflow Failure: {{ trigger.executionId }} has failed on {{ taskrun.startDate }}"
    sendgridApiKey: "{{ secret('SENDGRID_API_KEY') }}"
    executionId: "{{ trigger.executionId }}"

triggers:
  - id: on_failure
    type: io.kestra.plugin.core.trigger.Flow
    conditions:
      - type: io.kestra.plugin.core.condition.ExecutionStatusCondition
        in:
          - FAILED
          - WARNING
      - type: io.kestra.plugin.core.condition.ExecutionNamespaceCondition
        namespace: company
        comparison: PREFIX

Send Grid Mail Execution

Flow

Execution Status Condition

Execution Namespace Condition

More Related Blueprints

New to Kestra?

Use blueprints to kickstart your first workflows.

Get started with Kestra