Skip to content

Email Notifications ​

A DAG can email its own status: when a run fails, succeeds, or waits for a person, and when a chosen step fails. These settings live in the DAG file or in base.yaml, so they travel with the workflow. To manage email, Slack, Teams, Telegram, and webhook routing from the Web UI instead, use Notifications; for PagerDuty or SolarWinds incidents, use Incident Routing.

Quick Start ​

Put the SMTP server in base.yaml, so every DAG can use it:

yaml
# ~/.config/dagu/base.yaml
env:
  - SMTP_PASSWORD: ${SMTP_PASSWORD}  # from the server environment

smtp:
  host: smtp.example.com
  port: "587"
  username: alerts@example.com
  password: "${env.SMTP_PASSWORD}"

Then turn on the mail you want in the DAG:

yaml
mail_on:
  failure: true

error_mail:
  from: dagu@example.com
  to: oncall@example.com
  prefix: "[dagu]"

steps:
  - id: sync
    run: curl -fsS -X POST https://api.example.com/sync

Saved as orders-sync.yaml, a failed run sends oncall@example.com a mail titled [dagu] orders-sync (failed), with a summary of the run and its steps.

Which Mail Is Sent ​

EventTurn it on withUses
The run ends failedmail_on.failure: trueerror_mail
The run ends succeeded or partially_succeededmail_on.success: trueinfo_mail
The run starts waiting for a human task or approvalmail_on.wait: truewait_mail
A step failsmail_on_error: true on that steperror_mail
  • An event whose mail block is missing sends nothing. mail_on.success without info_mail sends no mail.
  • mail_on_error works without mail_on, but needs error_mail.
  • The run mail goes out after the lifecycle handlers finish.
  • With a root retry_policy, every failed attempt sends failure mail.
  • The runs of a backfill send only wait mail. To get the backfill summary by email, use an email channel.

Mail Settings ​

error_mail, info_mail, and wait_mail take the same fields:

FieldDescription
fromSender address
toOne address, or a list
prefixText placed before the subject
attach_logsAttach each step's stdout log

The subject is <prefix> <DAG name> (<status>). The HTML body lists the run ID, name, start and finish times, status, parameters, and error, followed by a table of the steps.

yaml
mail_on:
  failure: true
  success: true
  wait: true

error_mail:
  from: dagu@example.com
  to: [oncall@example.com, data-team@example.com]
  prefix: "[FAILED]"
  attach_logs: true

info_mail:
  from: dagu@example.com
  to: data-team@example.com
  prefix: "[OK]"

wait_mail:
  from: dagu@example.com
  to: approvers@example.com
  prefix: "[ACTION REQUIRED]"

steps:
  - id: load
    run: curl -fsS -X POST https://api.example.com/load
    mail_on_error: true

SMTP Configuration ​

FieldDescription
host, portSMTP server. Use the submission port, usually 587.
usernameAccount to sign in as. Required for OAuth.
passwordPassword or app password.
oauthOAuth 2.0 credentials, in place of password; see OAuth 2.0.
connectionA connection whose token signs in. Needs experimental_connections: true.

Dagu opens a plain connection and upgrades it with STARTTLS when the server offers it. Implicit TLS on port 465 is not supported for password or oauth. The same smtp block sends mail_on notifications and mail.send steps.

Base Configuration ​

An smtp block in base.yaml applies to every DAG, and a DAG's own smtp overrides it. error_mail, info_mail, wait_mail, and mail_on can be set there too.

Credentials From Environment or Secrets ​

smtp and the mail blocks are DAG and base-config fields; they do not read server DAGU_* environment variables. Import credentials into the DAG's scope with env: or secrets: and reference them, as in the Quick Start. Keep passwords, client secrets, refresh tokens, and service-account JSON out of the DAG file.

OAuth 2.0 ​

ProviderproviderRequired fieldsSMTP endpoint
Microsoft 365 applicationmicrosofttenant_id, client_id, client_secretsmtp.office365.com:587
Google Workspace service accountgoogle_service_accountservice_account_jsonsmtp.gmail.com:587
Google user refresh tokengoogle_refreshclient_id, client_secret, refresh_tokensmtp.gmail.com:587
  • smtp.username is required. It is the mailbox Dagu signs in as and, for a service account, the delegated user.
  • The endpoint is fixed. Omit host and port, or set them to the endpoint above.
  • oauth cannot be combined with password. Dagu requires STARTTLS, signs in with XOAUTH2 only when the server offers it, and never falls back to a password.
  • An smtp block that uses OAuth is replaced as a whole. When a base configuration uses OAuth and a DAG sets any smtp field, or a DAG switches a password-based base configuration to OAuth, the DAG's block replaces the inherited one. Repeat the full identity and credentials.

See SMTP Providers for setup per provider.

Run Snapshots and Retries ​

smtp inherited from base.yaml is not stored with a run. A retry, restart, or queued run uses the current base smtp together with any smtp in the original DAG YAML, locally and on distributed workers, which receive the base configuration with the task. Other saved settings, such as env, recipients, and mail_on, stay as they were when the run started. See Saved Runs.

When neither provides smtp, notifications are skipped and the run still runs. A mail.send step fails instead.

WARNING

The original DAG YAML stays in the run's history, including any SMTP credentials written directly in it. Values stored in env, distributed task payloads, and file-dependency bundles can also keep credentials. Import credentials as shown in Credentials From Environment or Secrets.

Send Custom Mail From a Step ​

For a message of your own, use the mail.send action, for example in a failure handler:

yaml
handler_on:
  failure:
    action: mail.send
    with:
      from: dagu@example.com
      to: oncall@example.com
      subject: "${context.dag.name} failed"
      message: |
        Run ${context.run.id} failed.
        Log: ${context.paths.log_file}
      attachments:
        - ${context.paths.log_file}

steps:
  - id: sync
    run: curl -fsS -X POST https://api.example.com/sync

mail.send uses the same smtp block, or a mail account with with.mailbox; see Mailbox. Status notifications always use smtp.

SMTP Providers ​

Microsoft 365 Application ​

Uses the OAuth client-credentials grant for unattended delivery.

yaml
env:
  - SMTP_TENANT_ID: ${SMTP_TENANT_ID}
  - SMTP_CLIENT_ID: ${SMTP_CLIENT_ID}
  - SMTP_CLIENT_SECRET: ${SMTP_CLIENT_SECRET}

smtp:
  username: alerts@contoso.com
  oauth:
    provider: microsoft
    tenant_id: "${env.SMTP_TENANT_ID}"
    client_id: "${env.SMTP_CLIENT_ID}"
    client_secret: "${env.SMTP_CLIENT_SECRET}"
  1. Register an application in Microsoft Entra ID.
  2. Grant it the Office 365 Exchange Online SMTP.SendAsApp application permission, with admin consent.
  3. Register the application's service principal in Exchange Online and give it access to the sender mailbox.
  4. Enable SMTP AUTH for the organization and the mailbox.

See Microsoft's SMTP OAuth guide and SMTP AUTH settings.

Gmail and Google Workspace ​

SetupAuthentication
Personal Gmail, or one manually managed mailboxGmail app password
Centrally managed Google Workspace automationGoogle Workspace service account
An existing OAuth client and refresh token, or a policy that prohibits app passwordsGoogle refresh token

App password. Turn on 2-Step Verification for the account and create a Google app password. Never use the account's normal password. App passwords can be unavailable for some work or school accounts, accounts that use only security keys, and Advanced Protection accounts; see Google's documentation.

yaml
env:
  - GMAIL_APP_PASSWORD: ${GMAIL_APP_PASSWORD}

smtp:
  host: smtp.gmail.com
  port: "587"
  username: alerts@gmail.com
  password: "${env.GMAIL_APP_PASSWORD}"

Service account. Impersonates the mailbox in smtp.username through domain-wide delegation, for Google Workspace domains only. Authorize the service account's numeric client ID in the Google Admin console with the https://mail.google.com/ scope. See Google's delegation guide and XOAUTH2 guide.

yaml
env:
  - GMAIL_SERVICE_ACCOUNT_JSON: ${GMAIL_SERVICE_ACCOUNT_JSON}

smtp:
  username: alerts@example.com
  oauth:
    provider: google_service_account
    service_account_json: "${env.GMAIL_SERVICE_ACCOUNT_JSON}"

Refresh token. Dagu refreshes access tokens but does not run the browser sign-in that creates the refresh token. The token must come from the same OAuth client, with offline access and the https://mail.google.com/ scope; see Google's offline access guide.

yaml
env:
  - GMAIL_CLIENT_ID: ${GMAIL_CLIENT_ID}
  - GMAIL_CLIENT_SECRET: ${GMAIL_CLIENT_SECRET}
  - GMAIL_REFRESH_TOKEN: ${GMAIL_REFRESH_TOKEN}

smtp:
  username: alerts@gmail.com
  oauth:
    provider: google_refresh
    client_id: "${env.GMAIL_CLIENT_ID}"
    client_secret: "${env.GMAIL_CLIENT_SECRET}"
    refresh_token: "${env.GMAIL_REFRESH_TOKEN}"

SendGrid ​

yaml
smtp:
  host: smtp.sendgrid.net
  port: "587"
  username: apikey
  password: "${env.SENDGRID_API_KEY}"

Amazon SES ​

yaml
smtp:
  host: email-smtp.us-east-1.amazonaws.com
  port: "587"
  username: "${env.SES_SMTP_USERNAME}"
  password: "${env.SES_SMTP_PASSWORD}"

Dagu is open source under the GNU General Public License v3.0.