Email from Modal Serverless Agent Functions

Send, read, and manage email from Modal's serverless containers — with MultiMail's API-level oversight ensuring every email is properly gated.


Modal is a serverless platform for running Python code in the cloud with instant container spin-up, GPU support, and scheduled functions. When your Modal functions run agent workloads that need email capabilities, MultiMail provides the email infrastructure with oversight that works at the API level — critical for serverless environments where process-level controls don't apply.

The serverless model means your code runs in ephemeral containers that spin up and down dynamically. MultiMail's stateless REST API is ideal for this pattern: each container makes authenticated API calls without needing persistent connections or local state for email management.

Integration is clean: add MultiMail API calls to your Modal functions. Whether it's a scheduled batch job, a webhook handler, or a GPU-powered ML pipeline that generates email reports, MultiMail handles delivery with oversight.

Built for Modal developers

API-Level Oversight for Serverless

In serverless environments, you can't rely on process-level controls. MultiMail's oversight is enforced at the API layer, so every email from every container instance is properly gated regardless of where or how the function runs.

Stateless API for Ephemeral Containers

Modal containers are ephemeral. MultiMail's REST API requires no persistent connections or local state — each API call is self-contained with Bearer token auth, perfect for serverless execution.

Scheduled Email Jobs

Modal's scheduled functions let you run recurring email tasks. MultiMail's oversight ensures scheduled jobs don't send emails unattended — each run's emails are queued for review.

Scale Without Email Safety Concerns

Modal scales containers automatically. Without oversight, a scaling event could multiply email sends. MultiMail's gated_send mode ensures every email from every container instance needs approval.


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. Read https://multimail.dev/llms.txt first, then connect the MultiMail MCP server exactly as documented there. In MultiMail, create a free inbox and set up a verified sending domain or verified sender before you add any send path. 2. In my Modal app, wire email through Modal’s real execution model: run the agent in a Modal Function inside a serverless container, use Modal Secrets for credentials or configuration, and call MultiMail only through the connected MCP tools. Do not invent an email API, webhook, endpoint, or custom transport. 3. Give the Modal agent three capabilities backed by MultiMail MCP actions: check the inbox for recent messages, draft a reply for developer review, and send or schedule an email only through MultiMail. Keep each capability small and auditable. 4. Send one test email from the verified sender to the free inbox, have the Modal agent check that inbox, draft a short reply, and prepare the outbound message. 5. Run the whole flow in MultiMail gated_send oversight mode, so every outbound email pauses for my approval before it sends. Do not use monitored or autonomous mode until I explicitly ask for it.

Step by step

1

Create a MultiMail Account and API Key

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

2

Install Modal

Install the Modal client and authenticate.

3

Store API Key as Modal Secret

Create a Modal secret named 'multimail' with your API key and mailbox ID.

4

Deploy Your Email Function

Create a Modal function that calls the MultiMail API and deploy it.

5

Approve Pending Emails

Review emails queued by your Modal functions in the MultiMail dashboard. Approve or reject before delivery.


Common questions

How do I store the MultiMail API key in Modal?
Use Modal's secrets management. Create a secret with 'modal secret create multimail MULTIMAIL_API_KEY=$MULTIMAIL_API_KEY' and reference it in your function decorator with secrets=[modal.Secret.from_name('multimail')]. The key is available as an environment variable inside the container.
Can Modal's auto-scaling cause duplicate emails?
Modal can run multiple container instances in parallel. If your function logic isn't idempotent, this could cause duplicate email sends. Use MultiMail's gated_send mode as a safety net — duplicates will appear in the approval queue where a human can catch them. Also design your functions to be idempotent.
Does MultiMail work with Modal's scheduled functions?
Yes. Modal's schedule parameter (Period or Cron) triggers function runs on a schedule. Each run makes fresh API calls to MultiMail. In gated_send mode, scheduled runs queue emails for review rather than sending automatically, preventing unattended email delivery.
Can I use MultiMail from Modal GPU functions?
Yes. MultiMail's REST API is a standard HTTPS call that works from any Modal function, including GPU-equipped containers. Use GPU functions for ML-powered email analysis or generation, then send results through MultiMail with full oversight.

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.