Mail
mail.send sends one email from a step. It sends through the DAG's smtp server, or through a mail account named with mailbox.
For emails about run status without a step, use mail_on notifications. To read, reply to, or organize received email, see Mailbox.
Basic Usage
secrets:
- name: SMTP_PASSWORD
ref: mail/smtp-password
smtp:
host: smtp.example.com
port: 587
username: alerts@example.com
password: ${SMTP_PASSWORD}
steps:
- id: notify
action: mail.send
with:
from: alerts@example.com
to: team@example.com
subject: Workflow Completed
message: The data processing workflow has completed.The step succeeds once the SMTP server accepts the message. Its log lists the sender, recipients, subject, and body, then a success line. mail.send publishes no outputs.
Configure SMTP
The DAG-level smtp block serves every mail.send step and every email notification of the DAG. Set it in the base configuration to share it across DAGs.
| Field | Description |
|---|---|
host, port | SMTP server. Use the submission port, usually 587: the connection upgrades with STARTTLS when the server offers it, and implicit TLS (port 465) is not used. |
username, password | Password sign-in. Read the password from secrets. |
oauth | OAuth 2.0 sign-in with provider: microsoft, google_service_account, or google_refresh, in place of password. |
connection | Experimental. A connection whose token signs in, in place of password or oauth. See Use a Connection. |
smtp fields resolve DAG values such as env, params, and secrets, not OS environment variables. Import an OS variable in env: first, such as - SMTP_USER: ${SMTP_USER}.
See SMTP Providers for Gmail, Microsoft 365, SendGrid, and AWS SES settings, and for the fields of each oauth provider.
Send to Several Recipients
to takes one address or a list:
steps:
- id: daily_report
action: mail.send
with:
from: reports@example.com
to:
- team@example.com
- manager@example.com
subject: Daily Report Ready
message: The daily report has been generated.Attach Files
steps:
- id: build_report
run: ./build-report.sh > ${context.paths.artifacts_dir}/report.csv
- id: send_report
depends: build_report
action: mail.send
with:
from: reports@example.com
to: management@example.com
subject: Weekly Report
message: The weekly report is attached.
attachments:
- ${context.paths.artifacts_dir}/report.csv- Use absolute paths. A relative path is read from the Dagu process's working directory, not the step's
working_dir. - A missing or unreadable file fails the step before it connects. An empty file is attached as an empty file.
- The attachment's content type comes from its file extension, or from its content when the extension implies none.
Write the Message
The body is sent as HTML. In plain text, line breaks become <br />. A body that starts with <!DOCTYPE html> is sent unchanged:
params:
- ENVIRONMENT: production
- VERSION: v1.2.3
steps:
- id: announce
action: mail.send
with:
from: deploy@example.com
to: devops@example.com
subject: Deployed ${params.VERSION} to ${params.ENVIRONMENT}
message: |
Deployment completed.
Environment: ${params.ENVIRONMENT}
Run: ${context.run.id}Notify on Failure
A mail.send step in handler_on reports the run's result:
handler_on:
failure:
action: mail.send
with:
from: alerts@example.com
to: oncall@example.com
subject: "Failed: ${context.dag.name}"
message: |
Run ${context.run.id} failed.
Log: ${context.paths.log_file}
steps:
- id: main
run: ./nightly-job.shTo retry a failed send, add retry_policy to the step as for any other step.
Send Through a Mail Account
With mailbox, the step sends through that account in mail_accounts instead of smtp, and from defaults to the account's address. in_reply_to then makes the message a threaded reply to an email the account received; see Send and Reply.
secrets:
- name: REPORTS_MAIL_PASSWORD
ref: mail/reports
mail_accounts:
reports@example.com:
provider: google
password: ${REPORTS_MAIL_PASSWORD}
steps:
- id: send_report
action: mail.send
with:
mailbox: reports@example.com
to: team@example.com
subject: Weekly Report
message: The weekly report is ready.Use a Connection
Experimental
Connections need experimental_connections: true in config.yaml. While they are off, a send through smtp.connection fails, and the run's other steps keep running.
smtp.connection signs in with a connection's token in place of password or oauth. It needs host and username. port defaults to 587, and port 465 uses TLS while any other uses STARTTLS. The token goes only to a host on the connection's bound hosts, with a verified certificate:
smtp:
host: smtp.example.com
username: alerts@example.com
connection: alerts-mail
steps:
- id: notify
action: mail.send
with:
from: alerts@example.com
to: team@example.com
subject: Workflow Completed
message: The workflow has completed.Configuration
| Field | Required | Default | Description |
|---|---|---|---|
to | Yes, unless in_reply_to supplies the sender | Recipient address, or a list of addresses. | |
from | No | Account address with mailbox | Sender address. Set it when sending through smtp. |
subject | No | Re: <subject> with in_reply_to | Subject line. |
message | No | Body, sent as HTML. See Write the Message. | |
attachments | No | List of file paths to attach. Use absolute paths. | |
mailbox | No | Address of a mail account in mail_accounts to send through instead of smtp. | |
in_reply_to | No | One email ID or email object to reply to. Requires mailbox. |
Errors and Limits
- No recipient fails the step with
no valid recipients specified, before connecting. - A missing or unreadable attachment fails the step before connecting, naming the file.
in_reply_towithoutmailbox, or naming more than one email, fails the step.smtp.oauthwithoutusernameor besidepassword, andsmtp.connectionbesidepasswordoroauth, fail validation.- The SMTP session, from connecting to sending, times out after 30 seconds.
- The body appears in the step log, so keep secrets out of
message.

