Skip to content

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.

The workflow builder's palette — the node groups, where Mail holds the Workflow handoff node, and beneath them the trigger groups, where Messaging holds the Workflow handoff trigger next to IMAP.The workflow builder's palette — the node groups, where Mail holds the Workflow handoff node, and beneath them the trigger groups, where Messaging holds the Workflow handoff trigger next to IMAP.
  • 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.
  1. 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.

  2. 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).

  3. Under Target workflow, choose the receiving workflow. Under Attachments, choose PDF attachments to hand over only PDF attachments, or All stored attachments.

  4. Save the reading workflow. Its next run hands the message over.

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.

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
  • 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.