Orchestrated Email Workflows with ControlFlow

Use ControlFlow's task-based workflow orchestration to build reliable, multi-step email processing pipelines with MultiMail's delivery infrastructure and human oversight.


ControlFlow is a workflow orchestration framework by Prefect that treats AI tasks as first-class workflow steps. It combines Prefect's workflow reliability with LLM-powered task execution and structured outputs. MultiMail provides the email infrastructure that ControlFlow workflows need to send, receive, and manage messages as part of larger business processes.

By integrating MultiMail with ControlFlow, you can model email tasks as explicit workflow steps with dependencies, structured results, and error handling. Email approval in MultiMail's gated_send mode becomes a workflow dependency that must resolve before downstream tasks proceed — making approval a first-class workflow primitive.

Connect ControlFlow to MultiMail by defining tasks that call the REST API. ControlFlow's dependency system ensures email operations execute in the correct order with proper error handling and retry logic.

Built for ControlFlow developers

Email Approval as Workflow Dependencies

ControlFlow's task dependency system can model email approval as an explicit step. MultiMail's pending queue becomes a dependency that must resolve before the workflow continues, making oversight a natural part of the flow.

Structured Email Results

ControlFlow tasks produce typed, structured results. Define result types for email operations — classification outcomes, delivery confirmations, thread summaries — and pass them between workflow steps with type safety.

Reliable Execution

Built on Prefect's workflow engine, ControlFlow provides retry logic, error handling, and observability for email workflows. Failed API calls retry automatically, and you can monitor workflow health through Prefect's dashboard.

Multi-Step Email Pipelines

Chain email tasks with dependencies: classify inbound mail, route to appropriate handlers, compose responses, approve, and send. ControlFlow ensures each step executes only when its dependencies are satisfied.

Agent Collaboration on Email

Assign different email tasks to specialized ControlFlow agents. A classification agent triages, a composition agent drafts, and a review agent validates — all coordinated through the workflow engine.


Try it with your agent

No code, no dashboard. Paste this to your AI agent — it connects MultiMail, creates an inbox, and builds the flow for you.

1. Get MultiMail ready: read https://multimail.dev/llms.txt, connect the MultiMail MCP server exactly as documented there, create a free inbox, and set up a verified sending domain. Use gated_send as the oversight mode from the start. 2. Wire it into ControlFlow: create a Python workflow using ControlFlow’s real primitives, with import controlflow as cf, cf.Agent for the email worker, and cf.Task steps inside a cf.flow. Define Python callable tool functions that delegate to the connected MultiMail MCP tools; use the exact tool names and arguments exposed by the MCP server, not invented API paths or headers. 3. Give the ControlFlow agent three capabilities: check the inbox, draft a reply, and send or schedule email. Pass those callable tools through ControlFlow’s tools mechanism on the relevant cf.Task steps, and model the work as ordered tasks: inbox check first, draft second, send third. 4. Send one test email from the verified sending domain to an address you control. The message should say it is a MultiMail plus ControlFlow gated_send test and should include the inbox address you created. 5. Run the workflow in gated_send so every outbound message pauses for developer review before anything sends. After confirming the pending test message in MultiMail, approve it, verify receipt, and leave the workflow in gated_send until the developer explicitly chooses monitored or autonomous later.

Step by step

1

Create a MultiMail Account and API Key

Sign up at multimail.dev, create a mailbox, and generate an API key. Your key will start with mm_live_.

2

Install Dependencies

Install ControlFlow and requests for calling the MultiMail API.

3

Define Tool Functions

Create Python functions that wrap MultiMail API endpoints for fetching inbox, sending email, and replying to threads.

4

Build Your Workflow

Define a ControlFlow @flow with tasks that have explicit dependencies. Assign agents and tools to each task.

5

Run and Monitor

Execute the flow. Monitor execution in Prefect's dashboard and review pending emails in MultiMail's dashboard.


Common questions

How does ControlFlow model email approval as a workflow dependency?
Create a task that sends email via MultiMail (which queues in gated_send mode), then a downstream task that polls the pending queue until approved. The dependency system ensures the workflow waits at the approval step before proceeding to follow-up actions.
Can I use Marvin functions inside ControlFlow tasks?
Yes. ControlFlow and Marvin are both by Prefect and designed to work together. Use Marvin's classify, extract, and generate functions within ControlFlow task handlers for specialized AI operations, while ControlFlow manages the workflow orchestration and dependency resolution.
How does ControlFlow handle failures in email operations?
ControlFlow inherits Prefect's retry and error handling. If a MultiMail API call fails (network error, rate limit), the task retries automatically based on your configuration. Failed tasks don't block unrelated downstream tasks, and you can inspect failures in the Prefect dashboard.
Can I schedule recurring email processing workflows?
Yes. ControlFlow flows can be deployed as Prefect deployments with schedules. Run your email processing workflow every 15 minutes, hourly, or on any cron schedule. Each run fetches new emails from MultiMail, processes them, and sends responses through the approval flow.
What oversight mode should I use with ControlFlow workflows?
Start with gated_send for new workflows so humans review every outbound email. As the workflow proves reliable, graduate to monitored mode where emails send immediately but remain auditable. Reserve autonomous mode for thoroughly tested, high-confidence workflows that have been running in gated_send for an extended period.

Explore more

The only agent email with a verifiable sender

Email infrastructure built for AI agents. Verifiable identity, graduated oversight, and a hosted MCP server. Formally verified in Lean 4.