LangChain email integration

Give a LangChain agent a real email mailbox — its own address on your domain, outbound sending, inbound replies as structured events, and thread context — using the official LoftBox Python SDK's LangChain toolkit.

Install

pip install loftbox[langchain]

Three lines to tools

from loftbox import LoftBox
from loftbox.integrations.langchain import LoftBoxToolkit

client = LoftBox(api_key="lb_live_xxx")
tools = LoftBoxToolkit(client).get_tools()

Then pass the tools to any tool-calling agent:

from langchain.agents import create_tool_calling_agent, AgentExecutor
from langchain_core.prompts import ChatPromptTemplate
from langchain_openai import ChatOpenAI

llm = ChatOpenAI(model="gpt-4o-mini")
prompt = ChatPromptTemplate.from_messages([
    ("system", "You are an agent that manages email."),
    ("human", "{input}"),
    ("placeholder", "{agent_scratchpad}"),
])
agent = create_tool_calling_agent(llm, tools, prompt)
AgentExecutor(agent=agent, tools=tools).invoke(
    {"input": "Check mailbox mb_123 for new mail and summarize it"}
)

A complete runnable example ships with the SDK: examples/langchain_agent.py.

Inbound mail is untrusted input

The moment your LangChain agent reads email, every received message is a potential prompt-injection payload. LoftBox scores every inbound message across 6 injection categories and exposes the risk signal on both the API and the webhook — so your agent (or your guard chain) can treat suspicious mail differently before it reaches the model.

What you get beyond tools

Get an API key — free Read the docs

Package: PyPI loftbox · Source: GitHub · Also see CrewAI, the MCP server, or how LoftBox compares.