Quick Start

Install the Dead Simple Email package with LangChain support:

terminal
pip install deadsimple[langchain] langchain langchain-openai

Initialize the toolkit and get your tools in two lines:

quick_start.py
from deadsimple.integrations.langchain import DeadSimpleEmailToolkit

toolkit = DeadSimpleEmailToolkit(api_key="dse_your_api_key")
tools = toolkit.get_tools()

That gives you a list of LangChain-compatible tools ready to pass into any agent. The toolkit handles authentication and API calls under the hood.

Available Tools

The toolkit provides six tools that cover the core email workflow: creating inboxes, sending messages, reading messages, and replying.

Tool Description
send_email Send an email from an inbox
read_emails Read recent emails from an inbox
read_email Read a single email with full body
reply_to_email Reply to an email (threading automatic)
create_inbox Create a new email inbox
list_inboxes List all email inboxes

Each tool includes a detailed description that the LLM uses to decide when and how to call it. The descriptions include parameter schemas with types and constraints, so the agent knows exactly what arguments to provide.

Full Example

Here is a complete working agent that can manage email on your behalf. It uses the create_tool_calling_agent pattern with AgentExecutor for a production-ready setup.

langchain_agent.py
from langchain_openai import ChatOpenAI
from langchain.agents import AgentExecutor, create_tool_calling_agent
from langchain_core.prompts import ChatPromptTemplate
from deadsimple.integrations.langchain import DeadSimpleEmailToolkit

# Initialize the LLM and toolkit
llm = ChatOpenAI(model="gpt-4o")
toolkit = DeadSimpleEmailToolkit(api_key="dse_your_api_key")
tools = toolkit.get_tools()

# Define the agent prompt
prompt = ChatPromptTemplate.from_messages([
    ("system", "You are an email assistant with access to Dead Simple Email."),
    ("human", "{input}"),
    ("placeholder", "{agent_scratchpad}"),
])

# Create the agent and executor
agent = create_tool_calling_agent(llm, tools, prompt)
executor = AgentExecutor(agent=agent, tools=tools)

# Run the agent
result = executor.invoke({"input": "Create an inbox and send a test email to hello@example.com"})
print(result["output"])

When you run this, the agent will:

  1. Call create_inbox to create a new inbox with an auto-generated email address
  2. Call send_email to send a test message from that inbox to hello@example.com
  3. Return a natural language summary of what it did

Using with Environment Variables

In production, pass your API key via environment variable instead of hardcoding it:

production_setup.py
import os
from deadsimple.integrations.langchain import DeadSimpleEmailToolkit

# Reads from DSE_API_KEY environment variable automatically
toolkit = DeadSimpleEmailToolkit()
tools = toolkit.get_tools()

# Or pass it explicitly
toolkit = DeadSimpleEmailToolkit(api_key=os.environ["DSE_API_KEY"])

Selecting Specific Tools

If your agent only needs a subset of email capabilities, you can filter the tools:

filtered_tools.py
toolkit = DeadSimpleEmailToolkit(api_key="dse_your_api_key")
all_tools = toolkit.get_tools()

# Only give the agent send and read capabilities
send_read_tools = [t for t in all_tools if t.name in {"send_email", "read_emails", "read_email"}]

Ready to build?

Create a free account and start integrating in minutes.

API Reference Get Started Free