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.
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.
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.
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.
MultiMail tracks email threads automatically. Your LangChain agent can retrieve full conversation history with get_thread, making context-aware replies natural.
Agents can search and manage contacts through search_contacts and add_contact tools, enabling relationship-aware email workflows within your LangChain chains.
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.
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.
@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.
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 resultUse LangChain's MCP adapter to connect directly to the MultiMail MCP server for automatic tool discovery.
Sign up at multimail.dev, create a mailbox, and generate an API key from your dashboard. Your key will start with mm_live_.
Install LangChain and the HTTP library for calling the MultiMail API.
pip install langchain langchain-openai requestsCreate LangChain @tool functions that wrap MultiMail API endpoints. At minimum, define send_email and check_inbox tools.
Build a tool-calling agent with a system prompt that explains the email context and oversight mode. Run it with AgentExecutor.
executor = AgentExecutor(agent=agent, tools=tools, verbose=True)
result = executor.invoke({"input": "Check my inbox"})If your mailbox uses gated_send mode (the default), review and approve pending emails in the MultiMail dashboard before they are delivered.
Email infrastructure built for AI agents. Verifiable identity, graduated oversight, and a 38-tool MCP server. Formally verified in Lean 4.