agentmail
agentmail-to/agentmail-skills
透過 AgentMail API 為 AI 代理程式建立專屬的電子郵件收件匣。適用於建置電子郵件代理程式、以程式化方式發送/接收電子郵件、管理收件匣、處理附件、使用標籤進行分類、建立待人為審核的草稿,或透過 webhooks/websockets 設定即時通知。支援透過 pod 實現的多租戶隔離。
...展開全部關於agentmail
AgentMail 是一款專為 AI 代理設計的「API 優先」電子郵件平台,透過對開發者友善的 SDK 提供程式化電子郵件功能。它解決了為 AI 代理建立專屬電子郵件身分,以及讓其能夠自主發送、接收和管理電子郵件通訊的挑戰。 開發人員無需從頭建置複雜的電子郵件基礎架構,只需幾行程式碼,即可迅速為其 AI 代理程式配置電子郵件收件匣,並將電子郵件功能整合至應用程式中。
該平台提供全面的電子郵件管理功能,包括可擴展的隨需信箱建立(支援自動生成或自訂電子郵件地址)、完整的訊息生命週期管理(含發送與回覆功能)、基於對話串的對話分組、標籤式組織,以及附件處理。 該平台同時支援純文字與 HTML 電子郵件格式,以確保最佳送達率,並透過 webhooks 和 websockets 提供即時通知功能。SDK 適用於 TypeScript/Node.js 及 Python 環境,並在兩種語言中提供一致的 API。
AgentMail 此服務非常適合開發人員打造由 AI 驅動的電子郵件代理程式、客戶支援自動化系統、外展與通訊工具,或任何需要程式化電子郵件功能的應用程式。它支援基於 pod 的隔離多租戶架構,因此非常適合需要多個代理程式或客戶擁有獨立電子郵件環境的 SaaS 應用程式。 無論您正在開發需要監控收件匣的 AI 助理、自動化跟進系統,或是由 AI 預先撰寫電子郵件供人工審核的草稿核准工作流程,AgentMail 皆能提供基礎架構與 API,以高效處理這些使用情境。
常見問題
AgentMail 支援哪些程式語言?
AgentMail [email protected] 提供對 TypeScript/Node.js 及 Python 的官方 SDK 支援。這兩套 SDK 均具備相同的核心功能,包括管理收件匣、收發訊息、透過標籤進行整理,以及處理郵件串。
我可以在AgentMail 中使用自訂電子郵件網域嗎?
是的,您在建立收件匣時,可以使用自訂使用者名稱和網域。若未指定自訂參數,AgentMail 會自動為您生成電子郵件地址,並使用預設的agentmail.to 網域。
AgentMail 是如何組織電子郵件對話的?
AgentMail [email protected] 會透過「討論串」將相關郵件歸類為對話,運作方式類似現代電子郵件客戶端。您可以列出討論串、依標籤篩選討論串,並檢索討論串中的所有郵件。此外,您還可使用自訂標籤來整理郵件,實現靈活的分類。
我需要同時發送純文字和 HTML 版本的電子郵件嗎?
是的,AgentMail 建議您始終同時發送純文字和 HTML 版本的郵件,以確保最佳的送達率。此舉可確保與不同電子郵件客戶端相容,並提高您的電子郵件成功送達的機率。
AgentMail 是否支援即時通知?
是的,AgentMail 支援透過 Webhooks 和 WebSockets 進行即時通知,當有新訊息送達或代理人的收件匣發生其他事件時,您的應用程式將立即收到通知。
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)





首頁
