agentmail
agentmail-to/agentmail-skills
Give AI agents their own email inboxes using the AgentMail API. Use when building email agents, sending/receiving emails programmatically, managing inboxes, handling attachments, organizing with labels, creating drafts for human approval, or setting up real-time notifications via webhooks/websockets. Supports multi-tenant isolation with pods.
...Expand allAbout agentmail
AgentMail is an API-first email platform designed specifically for AI agents, providing programmatic email capabilities through a developer-friendly SDK. It solves the challenge of giving AI agents their own email identities and the ability to autonomously send, receive, and manage email communications. Instead of building complex email infrastructure from scratch, developers can quickly provision email inboxes for their AI agents and integrate email functionality into their applications with just a few lines of code.
The platform provides comprehensive email management features including scalable on-demand inbox creation with auto-generated or custom email addresses, full message lifecycle management with sending and replying capabilities, thread-based conversation grouping, label-based organization, and attachment handling. It supports both plain text and HTML email formats for optimal deliverability, and includes real-time notification capabilities through webhooks and websockets. The SDK is available for both TypeScript/Node.js and Python environments, offering consistent APIs across both languages.
AgentMail is ideal for developers building AI-powered email agents, customer support automation systems, outreach and communication tools, or any application requiring programmatic email capabilities. It supports multi-tenant architectures with pod-based isolation, making it suitable for SaaS applications where multiple agents or customers need separate email environments. Whether you're building an AI assistant that needs to monitor an inbox, an automated follow-up system, or a draft approval workflow where AI prepares emails for human review, AgentMail provides the infrastructure and APIs to handle these use cases efficiently.
FAQ
What programming languages does AgentMail support?
AgentMail provides official SDK support for TypeScript/Node.js and Python. Both SDKs offer the same core functionality for managing inboxes, sending and receiving messages, organizing with labels, and handling threads.
Can I use custom email domains with AgentMail?
Yes, you can create inboxes with custom usernames and domains when creating an inbox. If you don't specify custom parameters, AgentMail will auto-generate an email address for you using the default agentmail.to domain.
How does AgentMail organize email conversations?
AgentMail uses threads to group related messages in a conversation, similar to how modern email clients work. You can list threads, filter them by labels, and retrieve all messages within a thread. Additionally, you can organize messages using custom labels for flexible categorization.
Do I need to send both plain text and HTML versions of emails?
Yes, AgentMail recommends always sending both text and html versions of your messages for best deliverability. This ensures compatibility across different email clients and improves the chances of your emails being delivered successfully.
Does AgentMail support real-time notifications?
Yes, AgentMail supports real-time notifications through webhooks and websockets, allowing your application to be notified immediately when new messages arrive or other events occur in your agent's inbox.
AgentMail SDK
AgentMail is an API-first email platform for AI agents. Install the SDK and initialize the client.
Installation
# TypeScript/Nodenpm install agentmail# Pythonpip install agentmail
Setup
import { AgentMailClient } from "agentmail";const client = new AgentMailClient({ apiKey: "YOUR_API_KEY" });
from agentmail import AgentMailclient = AgentMail(api_key="YOUR_API_KEY")
Inboxes
Create scalable inboxes on-demand. Each inbox has a unique email address.
// Create inbox (auto-generated address)const autoInbox = await client.inboxes.create();// Create with custom username and domainconst customInbox = await client.inboxes.create({ username: "support", domain: "yourdomain.com",});// List, get, deleteconst inboxes = await client.inboxes.list();const fetchedInbox = await client.inboxes.get("[email protected]");await client.inboxes.delete("[email protected]");
# Create inbox (auto-generated address)inbox = client.inboxes.create()# Create with custom username and domainfrom agentmail.inboxes.types import CreateInboxRequestinbox = client.inboxes.create( request=CreateInboxRequest(username="support", domain="yourdomain.com"),)# List, get, deleteinboxes = client.inboxes.list()inbox = client.inboxes.get(inbox_id="[email protected]")client.inboxes.delete(inbox_id="[email protected]")
Messages
Always send both text and html for best deliverability.
// Send messageawait client.inboxes.messages.send("[email protected]", { to: "[email protected]", subject: "Hello", text: "Plain text version", html: "<p>HTML version</p>", labels: ["outreach"],});// Reply to messageawait client.inboxes.messages.reply("[email protected]", "msg_123", { text: "Thanks for your email!",});// List and get messagesconst messages = await client.inboxes.messages.list("[email protected]");const message = await client.inboxes.messages.get("[email protected]", "msg_123");// Update labelsawait client.inboxes.messages.update("[email protected]", "msg_123", { addLabels: ["replied"], removeLabels: ["unreplied"],});
# Send messageclient.inboxes.messages.send( inbox_id="[email protected]", to="[email protected]", subject="Hello", text="Plain text version", html="<p>HTML version</p>", labels=["outreach"])# Reply to messageclient.inboxes.messages.reply( inbox_id="[email protected]", message_id="msg_123", text="Thanks for your email!")# List and get messagesmessages = client.inboxes.messages.list(inbox_id="[email protected]")message = client.inboxes.messages.get(inbox_id="[email protected]", message_id="msg_123")# Update labelsclient.inboxes.messages.update( inbox_id="[email protected]", message_id="msg_123", add_labels=["replied"], remove_labels=["unreplied"])
Threads
Threads group related messages in a conversation.
// List threads (with optional label filter)const threads = await client.inboxes.threads.list("[email protected]", { labels: ["unreplied"],});// Get thread detailsconst thread = await client.inboxes.threads.get("[email protected]", "thd_123");// Org-wide thread listingconst allThreads = await client.threads.list();
# List threads (with optional label filter)threads = client.inboxes.threads.list(inbox_id="[email protected]", labels=["unreplied"])# Get thread detailsthread = client.inboxes.threads.get(inbox_id="[email protected]", thread_id="thd_123")# Org-wide thread listingall_threads = client.threads.list()
Attachments
Send attachments with Base64 encoding. Retrieve from messages or threads.
// Send with attachmentconst content = Buffer.from(fileBytes).toString("base64");await client.inboxes.messages.send("[email protected]", { to: "[email protected]", subject: "Report", text: "See attached.", attachments: [ { content, filename: "report.pdf", contentType: "application/pdf" }, ],});// Get attachmentconst fileData = await client.inboxes.messages.getAttachment( "[email protected]", "msg_123", "att_456",);
import base64# Send with attachmentcontent = base64.b64encode(file_bytes).decode()client.inboxes.messages.send( inbox_id="[email protected]", to="[email protected]", subject="Report", text="See attached.", attachments=[{"content": content, "filename": "report.pdf", "content_type": "application/pdf"}])# Get attachmentfile_data = client.inboxes.messages.get_attachment( inbox_id="[email protected]", message_id="msg_123", attachment_id="att_456")
Drafts
Create drafts for human-in-the-loop approval before sending.
// Create draftconst draft = await client.inboxes.drafts.create("[email protected]", { to: "[email protected]", subject: "Pending approval", text: "Draft content",});// Send draft (converts to message)await client.inboxes.drafts.send("[email protected]", draft.draftId, {});
# Create draftdraft = client.inboxes.drafts.create( inbox_id="[email protected]", to="[email protected]", subject="Pending approval", text="Draft content")# Send draft (converts to message)client.inboxes.drafts.send(inbox_id="[email protected]", draft_id=draft.draft_id)
Pods
Multi-tenant isolation for SaaS platforms. Each customer gets isolated inboxes.
// Create pod for a customerconst pod = await client.pods.create({ clientId: "customer_123" });// Create inbox within podconst inbox = await client.pods.inboxes.create(pod.podId, {});// List inboxes scoped to podconst inboxes = await client.pods.inboxes.list(pod.podId);
# Create pod for a customerpod = client.pods.create(client_id="customer_123")# Create inbox within pod (pods.inboxes.create accepts flat kwargs)inbox = client.pods.inboxes.create(pod_id=pod.pod_id)# List inboxes scoped to podinboxes = client.pods.inboxes.list(pod_id=pod.pod_id)
Idempotency
Use clientId for safe retries on create operations.
const inbox = await client.inboxes.create({ clientId: "unique-idempotency-key",});// Retrying with same clientId returns the original inbox, not a duplicate
from agentmail.inboxes.types import CreateInboxRequestinbox = client.inboxes.create( request=CreateInboxRequest(client_id="unique-idempotency-key"),)# Retrying with same client_id returns the original inbox, not a duplicate
Real-Time Events
For real-time notifications, see the reference files:
- webhooks.md - HTTP-based notifications (requires public URL)
- websockets.md - Persistent connection (no public URL needed)
All Files
3 filesInstall agentmail
Download and extract the skill files to your .claude/skills/ directory.
Download ZIPClone the repository and copy the skill files to your project.
git clone https://github.com/agentmail-to/agentmail-skills/blob/main/agentmail/SKILL.md # Copy SKILL.md to your .claude/skills/ directory
Copy





Home
