Give a LangChain agent an email inbox
A LangChain agent uses Trotta Mail through its MCP server. With langchain 1.4 or later, MCPAdapter loads the tools from https://api.trotta.email/mcp with an API key or an OAuth sign-in, and create_agent takes them as they are. The agent can wait for mail, read a screened safe view, send and reply.
Updated
Install and connect
Install LangChain with MCP support. The langchain.mcp namespace needs langchain[mcp] 1.4.0 or later, and LangChain marks it as beta. The code follows the LangChain docs, checked on 2026-11-20.
pip install "langchain[mcp]"Load the tools, then give them to your agent. auth takes your Trotta Mail key, or the string "oauth" to sign in with Trotta Mail in a browser.
import os
from fastmcp.client import Client
from langchain.mcp import MCPAdapter
async def trotta_tools():
key = os.environ["TROTTA_MAIL_API_KEY"] # or "oauth" to sign in with Trotta Mail
async with MCPAdapter(Client("https://api.trotta.email/ mcp", auth=key)) as adapter:
return await adapter.list_tools()A complete example: inbox, wait, read, reply
This example gets an inbox, waits for a message, reads it and replies. Every Trotta Mail integration page runs the same four steps, so you can compare them. Step 1 is one HTTP call. The model takes steps 2 to 4 with tools.
1. Get an inbox
One call creates an inbox and an API key. It needs no account and no key.
curl -X POST https://api.trotta.email/ v1/ agents/ signup \
-H "Content-Type: application/ json" \
-d '{"name": "riley"}'The response carries api_key, inbox.address and a claim_url for the human responsible for the agent. Keep the key: it is shown once. Put it in TROTTA_MAIL_API_KEY.
2 to 4. Wait, read and reply
create_agent takes the loaded tools as they are. The model string is an Anthropic model id: swap in any chat model you have a key for.
import asyncio
import os
from fastmcp.client import Client
from langchain.agents import create_agent
from langchain.mcp import MCPAdapter
async def trotta_tools():
key = os.environ["TROTTA_MAIL_API_KEY"] # or "oauth" to sign in with Trotta Mail
async with MCPAdapter(Client("https://api.trotta.email/ mcp", auth=key)) as adapter:
return await adapter.list_tools()
async def main():
agent = create_agent("claude-sonnet-5-5", await trotta_tools())
result = await agent.ainvoke(
{"messages": [{"role": "user", "content": "Wait for the next message in my inbox, read it, and reply in one line."}]}
)
print(result["messages"][-1].content)
asyncio.run(main())Run it, then send a mail to the inbox address. The agent calls wait_for_message, then read_message, then reply_to_message. The loaded tools hold the connection, so they keep working after the adapter block ends.
Before a human claims the agent, it can receive from anyone and reply to anyone whose mail to it arrived authenticated. To write to new addresses, a human opens the claim_url.
What your agent reads
A LangChain agent reads screened mail, never the raw message. Each tool result joins the message history, and the model reads that history on every turn, so what the tools return is what the model works from. Trotta Mail returns three things.
- The verdict. Every message carries one, decided before the message is readable. Its action is
deliver,flag,holdorreject. - The safe view. Only what a human could see. Text hidden with CSS, comments and similar tricks is removed, instructions aimed at a model are replaced by a note, and risky links are defanged.
- Held mail, withheld. Dangerous mail waits outside the inbox for a human. The agent sees
withheld: trueand the reason in fixed words, and nothing the sender wrote.
The OWASP Top 10 for LLM Applications lists prompt injection as LLM01, the top risk, in both the 2025 edition and the current 2026 edition. An inbox is an open door for prompt injection, because anyone can write to an address. Screening before delivery removes or holds that text before it enters the agent's history.
No filter catches everything, so keep treating mail content as data, never as instructions. The verdict and the safe view are described in Concepts.
Going further
- MCP: every tool the server offers, including
thread_contextfor a whole conversation as one block. - Webhooks: a signed event posted to your endpoint when mail arrives.
- Live events: the same events over a stream, with no public endpoint.
- Pods: one isolated workspace per customer.
- Domains: agent inboxes on your own domain, on paid plans.
Questions
How does a LangChain agent send email?
Load the Trotta Mail tools with MCPAdapter and pass them to create_agent. The send_message and reply_to_message tools send mail, and every message is screened before it leaves.
Can a LangChain agent sign in with OAuth instead of an API key?
Yes. Pass the string oauth as auth and the client opens a browser to sign in with Trotta Mail. A human picks the inboxes the agent may use, and whether it may read, send or both.
Which LangChain version do I need?
The langchain.mcp namespace needs langchain 1.4.0 or later, installed with the mcp extra, and LangChain marks it as beta. Trotta Mail is a remote MCP server over Streamable HTTP, so any MCP client that speaks it can use the same URL and key.
What happens when an email carries a prompt injection?
Hidden text is removed and instructions aimed at a model are replaced by a note before the tool returns anything. A message judged dangerous is held for a human, and the agent sees only that it was withheld and why.
Is Trotta Mail made by LangChain?
No. Trotta Mail is an independent product that works with LangChain as a remote MCP server. It is not made or endorsed by LangChain.