Email Functions as Native Python with Magentic

Use Magentic's decorator pattern to make LLM-powered email composition feel like regular Python functions, backed by MultiMail's delivery infrastructure and oversight.


Magentic is a Python library that makes LLM calls look like regular function calls using decorators. Seamlessly integrating LLM capabilities into existing Python code with minimal boilerplate, it turns prompts into typed functions. MultiMail provides the email delivery infrastructure that sends what Magentic composes.

By combining Magentic with MultiMail, you can create email-composing functions that feel native to your Python codebase. Decorate a function with @prompt to describe the email task, and Magentic handles the LLM call. Then send the result through MultiMail's API with human oversight via gated_send mode.

Integration requires no special SDK — define Magentic-decorated functions for email composition and classification, then call the MultiMail REST API for delivery. The decorator pattern keeps your email logic clean and maintainable.

Built for Magentic developers

Native Python Feel

Magentic's decorator pattern makes email composition functions look and feel like regular Python code. Call compose_reply(email) and get a typed response. MultiMail sends it. No framework complexity in between.

Typed Email Composition

Return Pydantic models from Magentic functions for structured email data. Validate recipients, subjects, and body content at the type level, then send validated data to MultiMail.

Minimal Boilerplate

A Magentic email function is a decorator and a type hint. Compare that to agent frameworks that require tool registries, executors, and configuration objects. Less code means fewer bugs.

Composable Email Pipeline

Chain Magentic functions together: classify_email() | compose_reply() | send_via_multimail(). Each step is a simple function, making the pipeline easy to test, debug, and modify.

Async Support

Magentic supports async functions natively. Combined with async HTTP calls to MultiMail's API, you can process multiple emails concurrently without blocking.


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 to this agent, create a free inbox, and set up a verified sending domain or sender before attempting delivery. 2. Wire MultiMail into the Magentic app using Magentic’s decorator pattern: create normal Python functions for inbox checking, drafting replies, and sending mail, have those functions call the connected MultiMail MCP tools, then register those Python functions with Magentic prompt decorators through its functions mechanism so email composition feels like regular typed Python functions. 3. Give the agent three capabilities only: check the MultiMail inbox, draft a reply from message context using an LLM-powered Magentic function, and send or schedule email through MultiMail. Do not add any direct HTTP integration or unverified sending path. 4. Send a test email from the verified sender to an address I provide, then check the MultiMail inbox and draft a short reply so I can confirm the full receive, compose, and delivery loop works. 5. Run MultiMail in gated_send oversight mode for this integration. Before any email is sent or scheduled, show me the recipient, subject, body, and requested send time, and wait for my explicit approval.

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 Magentic and requests for calling the MultiMail API.

3

Define Email Functions

Create @prompt-decorated functions for email composition, classification, and summarization. Return Pydantic models for structured output.

4

Build Your Pipeline

Chain Magentic functions with MultiMail API calls: fetch inbox, classify emails, compose replies, and send through MultiMail.

5

Review Pending Emails

Approve or reject pending emails in the MultiMail dashboard when using gated_send mode.


Common questions

How does Magentic's decorator pattern work for email composition?
Decorate a function with @prompt and provide a prompt template with placeholders for parameters. Magentic calls the LLM with the filled template and returns a typed result. For email composition, the return type can be a Pydantic model with subject and body fields, giving you structured email data ready to send through MultiMail.
Can I use Magentic with models other than OpenAI?
Yes. Magentic supports multiple LLM backends including OpenAI, Anthropic, and LiteLLM for broader provider access. The decorator pattern works the same regardless of backend. MultiMail's REST API is completely provider-agnostic.
How does Magentic compare to full agent frameworks for email?
Magentic provides decorated functions, not agent loops. This is simpler for email composition and classification tasks where you don't need autonomous tool selection. For complex multi-step email workflows with branching logic, consider combining Magentic functions with an orchestrator like ControlFlow or LangGraph.
Can I use async Magentic functions with MultiMail?
Yes. Magentic supports async decorated functions. Combine with async HTTP calls using httpx to process multiple emails concurrently. This is useful for batch operations like classifying and replying to a full inbox.
How do I handle streaming for long email drafts?
Magentic supports streaming output from decorated functions. Use Annotated types with streaming support to get partial results as the LLM generates them. The final complete draft is then sent to MultiMail as a single API call, since email delivery requires the full message.

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.