Hand mail to another workflow
One mailbox has one reader: the workflow whose IMAP trigger polls it. When a second workflow needs the files of that mail (an invoice extractor that wants the PDFs, for example), the reading workflow hands the message over with a Workflow handoff node. The receiving workflow opts in with a Workflow handoff trigger and runs once per handed message, under its own budgets, resources and limits.


Prerequisites
Section titled “Prerequisites”- Both workflows belong to the same project.
- The reading workflow has an IMAP trigger that stores attachments, so the files exist on the server.
- The receiving workflow has no IMAP Ack node. A workflow that receives handoffs cannot hold one, and a workflow that holds one cannot opt in.
-
Open the receiving workflow and add a Workflow handoff trigger to its trigger lane. Under Source workflow, choose the workflow that reads the mailbox, then save. This is the opt-in: without it, nothing is handed over.
-
Open the reading workflow and add a Workflow handoff node from the Mail group of the palette, at the top level of the graph (not inside a loop or branch body).
-
Under Target workflow, choose the receiving workflow. Under Attachments, choose PDF attachments to hand over only PDF attachments, or All stored attachments.
-
Save the reading workflow. Its next run hands the message over.
What the receiving run gets
Section titled “What the receiving run gets”The receiving run starts with a trigger of kind workflow_handoff. Its
${{ trigger.… }} context holds the message address and headers (folder,
uid, message_id, from, to, subject, date), the handed attachments
and a handoff block naming the source run. The message body and the full
header list do not travel. A code node of the receiving run reads exactly the
handed files and nothing else.
Reading the result
Section titled “Reading the result”The node’s result in the source run names what happened:
| Field | What it holds |
|---|---|
target_run_id |
the run the message was handed to |
target_workflow_id |
the receiving workflow |
handed |
how many attachments were handed over |
reason |
present when handed is 0: why nothing was handed over |
A repeated hand-over of the same message (a rerun of the node, for example) finds the same receiving run and starts no second one.
| Reason | Meaning |
|---|---|
handoff_not_opted_in |
the receiving workflow has no enabled handoff trigger naming this workflow |
handoff_no_matching_stored_attachment |
the message has no stored attachment of the chosen kind; the node completes and no run starts |
handoff_cross_scope_refused |
the target belongs to another project |
handoff_target_unavailable |
the target workflow does not exist |
handoff_requires_original_publication |
the source run did not receive the message from its own IMAP trigger |
handoff_self_refused |
the node names its own workflow |
Limits
Section titled “Limits”- Only a run that received the message from its own IMAP trigger can hand it over. A run started by a mailbox backfill or a mail replay cannot.
- A receiving run cannot be replayed and cannot hand the message on to a third workflow. Replaying the source run replays the source run only.
- Both workflows must be in the same project.
Related
Section titled “Related”- Set up an IMAP trigger — the reading workflow’s trigger and how attachments are stored
- Build your first workflow — the
trigger lane, the palette and
${{ trigger.… }}templating