Skip to content

Send and receive email

Two statements connect a workflow to email. Each one is a line in a formula node’s node file:

Statement What it does
toEmail(recipient) Sends an email, for the table or for each row; the rows pass through
fromEmail() Reads the email that started the run, as rows

The Learn connecting workflows to APIs and email catalog has a lesson for each: 04 Send an email and 05 Start a workflow from an email.

toEmail("finance@acme.example.com")
.subject("Overdue invoices")
.body("The overdue invoices are attached.")
.format("csv")
Option Use
.subject(text) The subject line
.body(text) The message text
.format("csv" | "tsv" | "xlsx" | "json") Attaches the rows as a file in that format; without it the email carries no data
.attach(path, …) Attaches Workspace files, relative to the node file; a file the same node wrote earlier in the run with toFile is attached as written
.from(agent("<agent id>")) Sends as that agent, from its address, so replies reach its mailbox

The recipient is one address, or several separated by commas. The rows pass through unchanged, so an email can be a step in the middle of a workflow.

Put eachRow() in front to send one email for each row. The recipient, subject, and body may then read the row:

setProp("email_subject", "Invoice " + prop("invoice_id") + " is " + format(prop("days_overdue")) + " days overdue")
eachRow().toEmail(prop("contact_email"))
.subject(prop("email_subject"))
.body("Dear " + prop("customer") + ", please arrange payment.")

A per-row send that fails is recorded on that row and the other rows still send. A send for the whole table that fails fails the node.

Render the body once with a template and keep it as a context value, then send it:

context("body").fromTemplate(`{{ numRows }} invoices are overdue:
{% for r in rows %}- {{ r.invoice_id }} {{ r.customer }} {{ r.amount }} {{ r.ccy }}
{% endfor %}`)
.send("invoice_id", "customer", "amount", "ccy")
toEmail("finance@acme.example.com")
.subject("Overdue invoices")
.body(context("body"))

See Templates, queries, and scripts for templates.

Email leaves through your deployment’s mail service as an agent: the agent named in .from(agent(...)), or else the Workspace owner’s default chat agent. The agent’s send whitelist must match every recipient; an empty send whitelist blocks every send. See Agent email.

A node that sends email carries the exporting trigger condition, so it sends only when no node upstream raised a warning or error. See Formula node.

fromEmail() reads the email that started the run. The node needs an inbound email trigger: add the node with the Receive an email preset, or choose Email under Receives on the node’s fromEmail Form card. The node then has its own inbound address on your tenant mail domain, and every email sent to it starts a run.

fromEmail()
setProp("attachment_count", prop("attachments").count())
setProp("reference", prop("subject").match("[A-Z]{2,5}-[0-9]+").first())
keepProps("from", "sent", "subject", "reference", "attachment_count")

Each message is one row with the columns from, to, cc, sent, subject, body, messageId, and attachments. context("mail").fromEmail() keeps the message as one value instead, and the rows pass through.

A run started with Run has no email, so the node has no rows. Inbound email and the tenant mail domain are switched on for your deployment by your platform team (see Fontana CLI); until then a node has no inbound address.