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:
# ~/.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:
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/syncSaved 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
| Event | Turn it on with | Uses |
|---|---|---|
The run ends failed | mail_on.failure: true | error_mail |
The run ends succeeded or partially_succeeded | mail_on.success: true | info_mail |
| The run starts waiting for a human task or approval | mail_on.wait: true | wait_mail |
| A step fails | mail_on_error: true on that step | error_mail |
- An event whose mail block is missing sends nothing.
mail_on.successwithoutinfo_mailsends no mail. mail_on_errorworks withoutmail_on, but needserror_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:
| Field | Description |
|---|---|
from | Sender address |
to | One address, or a list |
prefix | Text placed before the subject |
attach_logs | Attach 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.
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: trueSMTP Configuration
| Field | Description |
|---|---|
host, port | SMTP server. Use the submission port, usually 587. |
username | Account to sign in as. Required for OAuth. |
password | Password or app password. |
oauth | OAuth 2.0 credentials, in place of password; see OAuth 2.0. |
connection | A 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
| Provider | provider | Required fields | SMTP endpoint |
|---|---|---|---|
| Microsoft 365 application | microsoft | tenant_id, client_id, client_secret | smtp.office365.com:587 |
| Google Workspace service account | google_service_account | service_account_json | smtp.gmail.com:587 |
| Google user refresh token | google_refresh | client_id, client_secret, refresh_token | smtp.gmail.com:587 |
smtp.usernameis required. It is the mailbox Dagu signs in as and, for a service account, the delegated user.- The endpoint is fixed. Omit
hostandport, or set them to the endpoint above. oauthcannot be combined withpassword. Dagu requires STARTTLS, signs in with XOAUTH2 only when the server offers it, and never falls back to a password.- An
smtpblock that uses OAuth is replaced as a whole. When a base configuration uses OAuth and a DAG sets anysmtpfield, 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:
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/syncmail.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.
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}"- Register an application in Microsoft Entra ID.
- Grant it the Office 365 Exchange Online
SMTP.SendAsAppapplication permission, with admin consent. - Register the application's service principal in Exchange Online and give it access to the sender mailbox.
- Enable SMTP AUTH for the organization and the mailbox.
See Microsoft's SMTP OAuth guide and SMTP AUTH settings.
Gmail and Google Workspace
| Setup | Authentication |
|---|---|
| Personal Gmail, or one manually managed mailbox | Gmail app password |
| Centrally managed Google Workspace automation | Google Workspace service account |
| An existing OAuth client and refresh token, or a policy that prohibits app passwords | Google 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.
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.
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.
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
smtp:
host: smtp.sendgrid.net
port: "587"
username: apikey
password: "${env.SENDGRID_API_KEY}"Amazon SES
smtp:
host: email-smtp.us-east-1.amazonaws.com
port: "587"
username: "${env.SES_SMTP_USERNAME}"
password: "${env.SES_SMTP_PASSWORD}"
