Durable AI Email Workflows with Temporal and MultiMail

Pair Temporal's durable execution model with MultiMail's graduated oversight to build email workflows that pause for approval, survive process crashes, and resume exactly where they left off.


Temporal is a durable workflow engine that persists every step of a long-running process. When an AI agent needs to send an email that requires human approval, Temporal can pause the workflow indefinitely—surviving restarts, deploys, and network failures—then resume the moment approval arrives.

MultiMail's `gated_send` and `gated_all` oversight modes map directly onto Temporal's timer and signal primitives. A workflow activity calls `send_email` via the MultiMail API, receives a pending approval ID, then waits on a Temporal signal that fires when the human approves or rejects. No polling loops, no external state storage, no lost approvals.

This pattern is especially useful for high-stakes outbound email in regulated industries: loan offer notifications, patient communications, contract delivery. Temporal guarantees at-least-once execution of each activity; MultiMail guarantees the human stays in the loop before anything leaves the system.

Built for Temporal + AI Agents developers

Approvals as first-class workflow signals

MultiMail's approval queue exposes webhook events when a human approves or rejects a pending send. These events map cleanly to Temporal workflow signals, letting you pause a workflow at the send step and resume it without any external coordination logic.

Durable execution survives oversight latency

Human approval may take hours or days. Temporal workflows can pause for weeks without losing state. Combined with MultiMail's persistent approval queue, you never lose a pending send because a worker restarted.

Graduated trust over time

Start with `gated_all` while building confidence, then promote a mailbox to `monitored` or `autonomous` via the MultiMail API. Temporal workflow logic doesn't need to change—oversight behavior is a configuration property on the mailbox, not embedded in workflow code.

Retries without duplicate sends

Temporal retries failed activities automatically, but MultiMail's idempotency keys prevent duplicate email delivery. Pass a deterministic key derived from the workflow ID and activity attempt number to ensure exactly-once delivery semantics.

Full thread context across workflow steps

MultiMail's `get_thread` endpoint retrieves complete conversation history. Temporal activities can fetch this context at any step, letting an AI agent craft replies with full awareness of prior exchanges without re-fetching from upstream sources.


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.

You are integrating MultiMail into my Temporal + AI Agents workflow. Use only documented Temporal and MultiMail features, and do not invent any MultiMail API, webhook, endpoint, or header. 1. Get MultiMail ready: read https://multimail.dev/llms.txt, connect the MultiMail MCP server to this agent environment, create a free inbox, and set up a verified sending domain or sender in MultiMail. 2. Wire MultiMail into Temporal + AI Agents using Temporal Workflows for durable orchestration and Temporal Activities for side-effecting agent tool calls. Keep the Workflow deterministic; call MultiMail only from Activities or registered agent tools/functions, and use Temporal Signals or Updates for human approval points. 3. Give the agent three email capabilities through the connected MultiMail MCP server: check the inbox for new messages, draft a reply by composing email content without sending, and send or schedule email only through MultiMail. 4. Create a small test Workflow that asks the agent to check the MultiMail inbox, draft a reply to a test message, and prepare a test email to my own address from the verified sender. 5. Run the test in MultiMail gated_send mode so every outbound email pauses for developer review before it sends. Verify that the Workflow survives a worker restart and resumes at the approval point, then approve the test email and confirm the Workflow completes.

Step by step

1

Install Temporal SDK and configure your worker

Install the Temporal TypeScript SDK and set up a worker that runs on the `email-agent` task queue. The worker registers your workflow and activity functions.

2

Create a MultiMail mailbox in gated_send mode

Create a mailbox via the MultiMail API with `gated_send` oversight so all outbound messages wait for human approval. Retrieve your API key from the MultiMail dashboard.

3

Register a webhook for approval events

Configure MultiMail to deliver `approval.approved` and `approval.rejected` events to your webhook endpoint. This endpoint will signal your Temporal workflows when humans act on pending sends.

4

Deploy workflow, activities, and webhook handler

Register your workflow and activities with the Temporal worker, deploy the webhook handler to your API, and start a Temporal workflow for each email that needs to be sent. Use the workflow ID as the correlation key between MultiMail events and Temporal executions.


Common questions

What happens if the Temporal worker restarts while waiting for approval?
Nothing. Temporal persists the full workflow event history in its database. When the worker restarts, the workflow resumes from exactly where it paused. The `condition()` call that blocks on `approvalSignal` re-evaluates against the in-memory state rebuilt from history—no data is lost.
How do I correlate a MultiMail webhook event back to the right Temporal workflow?
Set the Temporal workflow ID as a custom metadata field when calling the MultiMail `send_email` endpoint, or store the mapping in Temporal's memo or search attributes. When the webhook fires, read the workflow ID from the event payload and call `client.workflow.getHandle(workflowId).signal(...)` to resume the correct instance.
Can a Temporal workflow handle both sending and receiving emails for the same thread?
Yes. Combine `send_email` for outbound steps with `check_inbox` and `get_thread` for inbound polling activities. Use Temporal timers (`sleep`) to wait for replies, and cancel the timer early via a signal if an inbound message arrives before the timeout.
Does using Temporal affect MultiMail's idempotency guarantees?
Temporal retries failed activities, which could cause duplicate API calls. Prevent duplicate sends by passing an idempotency key derived from the workflow ID and activity attempt number: `${workflowId}-${attemptNumber}`. MultiMail deduplicates on this key, so retries are safe.
How do I escalate to a stricter oversight mode mid-workflow if something looks suspicious?
Call the MultiMail API from a Temporal activity to update the mailbox oversight mode: `PATCH https://api.multimail.dev/mailboxes/{id}` with `{ "oversight_mode": "gated_all" }`. Subsequent email activities in the same or future workflows will pick up the stricter mode automatically.
Can I use Temporal with Python instead of TypeScript?
Yes. Temporal has a Python SDK (`pip install temporalio`). MultiMail has no Python SDK—you call its REST API directly with `requests` or `httpx`. Inside an activity decorated with `@activity.defn`, just `requests.post("https://api.multimail.dev/v1/mailboxes/{mailbox_id}/send", headers={"Authorization": "Bearer $MULTIMAIL_API_KEY", "Content-Type": "application/json"}, json={"to": [to], "subject": subject, "markdown": body})`. The same idempotency and signal patterns apply.

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.