Give Your LangChain Agents Email Superpowers

Connect LangChain's tool-calling agents to MultiMail for sending, reading, and managing email — with configurable human oversight at every step.


LangChain is the most widely adopted framework for building LLM-powered applications. Its agent system supports tool calling, allowing models to interact with external services like email. MultiMail provides the email infrastructure layer that LangChain agents need to send, receive, and manage messages on behalf of users.

By integrating MultiMail with LangChain, your agents can compose and send emails, check inboxes, manage contacts, and handle threads — all while respecting human oversight boundaries. The default gated_send mode means your agent drafts emails but a human approves before delivery, building trust incrementally.

You can connect LangChain to MultiMail using the MCP server (@multimail/mcp-server) for native tool integration, or call the REST API directly using custom tools. Both approaches give your agents access to the full suite of email capabilities.

Built for LangChain developers

Built for Agents, Not Humans

MultiMail's API is designed for programmatic access. Every action — sending, reading, replying — is an API call your LangChain agent can invoke as a tool, with structured inputs and outputs.

Graduated Trust via Oversight Modes

Start with gated_send (agent composes, human approves) and progress to monitored or autonomous as trust builds. LangChain agents can query their current oversight level and adapt behavior accordingly.

MCP Server Integration

The @multimail/mcp-server package exposes email tools in the Model Context Protocol format. LangChain's MCP tool adapter lets your agent call send_email, check_inbox, and other tools natively.

Thread-Aware Conversations

MultiMail tracks email threads automatically. Your LangChain agent can retrieve full conversation history with get_thread, making context-aware replies natural.

Contact Management

Agents can search and manage contacts through search_contacts and add_contact tools, enabling relationship-aware email workflows within your LangChain chains.


Get started in minutes

Define MultiMail Tools for LangChain
python
import requests
from langchain.tools import tool

MULTIMAIL_API = "https://api.multimail.dev/v1"
HEADERS = {"Authorization": "Bearer mm_live_your_api_key"}

@tool
def send_email(to: str, subject: str, body: str, mailbox_id: str) -> str:
    """Send an email through MultiMail. In gated_send mode, this creates a pending draft for human approval."""
    resp = requests.post(f"{MULTIMAIL_API}/send", headers=HEADERS, json={
        "mailbox_id": mailbox_id,
        "to": to,
        "subject": subject,
        "body": body
    })
    return resp.json()

@tool
def check_inbox(mailbox_id: str, limit: int = 10) -> str:
    """Check the inbox for a given mailbox. Returns recent messages."""
    resp = requests.get(
        f"{MULTIMAIL_API}/mailboxes/{mailbox_id}/inbox",
        headers=HEADERS,
        params={"limit": limit}
    )
    return resp.json()

Create custom LangChain tools that call the MultiMail REST API to send emails and check inboxes.

Build an Email Agent with Tool Calling
python
from langchain_openai import ChatOpenAI
from langchain.agents import create_tool_calling_agent, AgentExecutor
from langchain_core.prompts import ChatPromptTemplate

llm = ChatOpenAI(model="gpt-4o")
tools = [send_email, check_inbox]

prompt = ChatPromptTemplate.from_messages([
    ("system", "You are an email assistant. Use the provided tools to "
     "send and read emails. The mailbox is in gated_send mode, so "
     "sent emails will be queued for human approval before delivery."),
    ("human", "{input}"),
    ("placeholder", "{agent_scratchpad}")
])

agent = create_tool_calling_agent(llm, tools, prompt)
executor = AgentExecutor(agent=agent, tools=tools, verbose=True)

result = executor.invoke({
    "input": "Check my inbox and summarize any unread messages"
})

Create a LangChain agent that can send and read email using the MultiMail tools.

Reply to Email Threads
python
@tool
def reply_email(message_id: str, body: str) -> str:
    """Reply to an email by message ID. Maintains the thread context."""
    resp = requests.post(f"{MULTIMAIL_API}/reply", headers=HEADERS, json={
        "message_id": message_id,
        "body": body
    })
    return resp.json()

@tool
def get_thread(thread_id: str) -> str:
    """Get all messages in an email thread for context."""
    resp = requests.get(
        f"{MULTIMAIL_API}/threads/{thread_id}",
        headers=HEADERS
    )
    return resp.json()

"cm"># Add to your agent's tool list
tools = [send_email, check_inbox, reply_email, get_thread]

Add a reply tool so your agent can respond to emails within their original thread context.

Connect via MCP Server
python
from langchain_mcp_adapters.client import MultiServerMCPClient
from langchain.agents import create_tool_calling_agent, AgentExecutor

async def create_email_agent():
    async with MultiServerMCPClient({
        "multimail": {
            "command": "npx",
            "args": ["-y", "@multimail/mcp-server"],
            "env": {"MULTIMAIL_API_KEY": "mm_live_your_api_key"}
        }
    }) as client:
        tools = client.get_tools()  "cm"># Auto-discovers all MultiMail tools
        agent = create_tool_calling_agent(llm, tools, prompt)
        executor = AgentExecutor(agent=agent, tools=tools)
        result = await executor.ainvoke({
            "input": "Send a follow-up email to the last thread"
        })
        return result

Use LangChain's MCP adapter to connect directly to the MultiMail MCP server for automatic tool discovery.


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 Dependencies

Install LangChain and the HTTP library for calling the MultiMail API.

bash
pip install langchain langchain-openai requests
3

Define Your Email Tools

Create LangChain @tool functions that wrap MultiMail API endpoints. At minimum, define send_email and check_inbox tools.

4

Create and Run Your Agent

Build a tool-calling agent with a system prompt that explains the email context and oversight mode. Run it with AgentExecutor.

bash
executor = AgentExecutor(agent=agent, tools=tools, verbose=True)
result = executor.invoke({"input": "Check my inbox"})
5

Approve Pending Emails

If your mailbox uses gated_send mode (the default), review and approve pending emails in the MultiMail dashboard before they are delivered.


Common questions

Does LangChain have a native MultiMail integration?
There is no official langchain-multimail package. You integrate MultiMail by either defining custom @tool functions that call the REST API, or by connecting to the @multimail/mcp-server via LangChain's MCP adapter. Both approaches give your agent full access to MultiMail's email tools.
What happens when my agent sends an email in gated_send mode?
In gated_send mode, the API returns a success response with a pending status. The email is queued for human review in the MultiMail dashboard. Once approved, it is delivered. Your agent can check the status of pending emails using the list_pending tool or API endpoint.
Can I use LangChain's async features with MultiMail?
Yes. The MultiMail REST API works with any HTTP client, so you can use aiohttp or httpx for async requests. If you use the MCP server integration, the MCP client adapter already supports async operations natively through LangChain's ainvoke pattern.
How do I handle email attachments?
The MultiMail API supports attachments via the send and reply endpoints. Pass attachments as base64-encoded content in the request body. Your LangChain tool can accept file paths, encode them, and include them in the API call.
Can my LangChain agent manage multiple mailboxes?
Yes. Use the list_mailboxes tool or GET /mailboxes endpoint to discover available mailboxes. Your agent can then route emails through specific mailboxes by passing the appropriate mailbox_id to send and inbox tools. This is useful for agents handling different departments or personas.
Is there rate limiting on the MultiMail API?
Rate limits depend on your plan tier. The Starter (free) plan allows 200 emails per month, while paid plans range from 5,000 to 150,000. The API returns standard 429 responses when limits are reached, which your LangChain agent can handle with retry logic.

Explore more

The only agent email with a verifiable sender

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