API Documentation
Base URL: https://api.theagentmail.net
Getting started
AgentMail gives your AI agent its own email address. Here's how to set it up.
1. Sign in and create an org
Sign in with your personal email (Gmail, Outlook, ProtonMail, etc.). Then create an organization from the dashboard. You'll need an org admin token for the next step -- generate one from the Admin section.
2. Create an email account for your agent
curl -X POST https://api.theagentmail.net/v1/accounts \
-H "Authorization: Bearer am_org_..." \
-H "Content-Type: application/json" \
-d '{"address": "my-agent@theagentmail.net"}'3. Create a token scoped to that account
Use the account ID from the previous response. This token only has access to this one mailbox -- safe to give to your agent.
curl -X POST https://api.theagentmail.net/v1/accounts/ACCOUNT_ID/api-keys \
-H "Authorization: Bearer am_org_..." \
-H "Content-Type: application/json" \
-d '{"name": "my-agent-key"}'Save the key from the response. It's only shown once.
4. Give your agent the token and this docs page
Pass the account token and https://theagentmail.net/docs to your AI agent. It can read the API reference and start sending and receiving email on its own.
Authentication
All API endpoints require a Bearer token in the Authorization header.
Authorization: Bearer am_...There are two types of tokens:
Org tokens
Full access to all accounts in your organization. Create and delete accounts, send and receive email, manage webhooks, and manage balance. Created from the dashboard.
Account tokens
Scoped to a single email account. Can send and receive email, manage webhooks, and view account info. Cannot access other accounts or create new ones (returns 403). Created programmatically via POST /v1/accounts/:id/api-keys.
Account tokens can use shortcut routes that omit the account ID -- the server infers it from the token. For example, POST /v1/messages instead of POST /v1/accounts/:accountId/messages. See each endpoint section for the shortcut path.
Accounts
/v1/accountsCreate a new email account. First account is free for 30 days upon phone verification. Additional accounts cost $1/month from your prepaid balance.
Request body
{
"address": "my-agent@theagentmail.net",
"displayName": "My Agent" // optional
}Response (201)
{
"data": {
"id": "abc123",
"address": "my-agent@theagentmail.net",
"displayName": "My Agent",
"createdAt": 1709136000000,
"expiresAt": 1711728000000,
"isFrozen": false,
"sendsThisMonth": 0
}
}Reserved addresses (uri, support) cannot be created.
/v1/accountsList all email accounts in your organization.
Response
{
"data": [
{
"id": "abc123",
"address": "my-agent@theagentmail.net",
"displayName": "My Agent",
"createdAt": 1709136000000,
"expiresAt": 1711728000000,
"isFrozen": false,
"sendsThisMonth": 0
}
]
}/v1/accounts/:accountIdGet details for a specific account. With an account token: GET /v1/account
/v1/accounts/:accountIdDelete an email account. With an account token: DELETE /v1/account
Permanently deletes the mailbox along with its messages, attachments, and webhooks. The address becomes available for reuse.
Messages
/v1/accounts/:accountId/messagesSend an email from this account. 1,000 sends/month included per mailbox. With an account token: POST /v1/messages
Request body
{
"to": ["human@example.com"],
"cc": ["other@example.com"], // optional
"bcc": ["hidden@example.com"], // optional
"subject": "Hello from my agent",
"text": "Plain text body",
"html": "<p>HTML body</p>", // optional
"inReplyTo": "<msgid@example>", // optional, for threading
"references": "<msgid@example>", // optional
"attachments": [ // optional
{
"filename": "report.pdf",
"contentType": "application/pdf",
"content": "base64-encoded-data"
}
]
}Response (201)
{
"data": {
"id": "msg_123",
"from": "my-agent@theagentmail.net",
"to": ["human@example.com"],
"subject": "Hello from my agent",
"direction": "outbound",
"status": "queued",
"timestamp": 1709136000000
}
}/v1/accounts/:accountId/messagesList all messages (inbound and outbound) for this account, sorted by most recent first. With an account token: GET /v1/messages
Response
{
"data": [
{
"id": "msg_123",
"from": "sender@gmail.com",
"to": ["my-agent@theagentmail.net"],
"subject": "Re: Hello",
"direction": "inbound",
"status": "received",
"timestamp": 1709137000000
}
]
}/v1/accounts/:accountId/messages/:messageIdGet a single message with full body content and attachment metadata. With an account token: GET /v1/messages/:messageId
Response
{
"data": {
"id": "msg_123",
"from": "sender@gmail.com",
"to": ["my-agent@theagentmail.net"],
"subject": "Re: Hello",
"text": "Full message body...",
"html": "<p>Full HTML body...</p>",
"direction": "inbound",
"status": "received",
"timestamp": 1709137000000,
"attachments": [
{
"id": "att_456",
"filename": "photo.jpg",
"contentType": "image/jpeg",
"size": 245000
}
]
}
}Attachments
/v1/accounts/:accountId/messages/:messageId/attachments/:attachmentIdGet a signed download URL for an attachment. The URL is valid for 1 hour. With an account token: GET /v1/messages/:messageId/attachments/:attachmentId
Response
{
"data": {
"url": "https://storage.googleapis.com/...",
"filename": "photo.jpg",
"contentType": "image/jpeg",
"expiresAt": 1709140600000
}
}Webhooks
Register a webhook URL to get notified when your account receives email. We'll POST to your URL within seconds of delivery.
/v1/accounts/:accountId/webhooksRegister a webhook for inbound email notifications. With an account token: POST /v1/webhooks
Request body
{
"url": "https://my-agent.example.com/inbox"
}Response (201)
{
"data": {
"id": "wh_789",
"url": "https://my-agent.example.com/inbox",
"secret": "whsec_abc123...",
"active": true,
"createdAt": 1709136000000
}
}Save the secret -- it's only returned on creation. Use it to verify webhook signatures.
/v1/accounts/:accountId/webhooksList all webhooks for this account. With an account token: GET /v1/webhooks
/v1/accounts/:accountId/webhooks/:webhookIdDelete a webhook. With an account token: DELETE /v1/webhooks/:webhookId
Webhook delivery format
When an email arrives, we POST a JSON payload to your webhook URL:
{
"event": "email.received",
"data": {
"id": "msg_123",
"account_id": "abc123",
"account_address": "my-agent@theagentmail.net",
"from": "sender@gmail.com",
"to": ["my-agent@theagentmail.net"],
"cc": ["other@example.com"],
"subject": "Hello",
"text": "Message body...",
"html": "<p>Message body...</p>",
"messageId": "<external-msgid@gmail.com>",
"inReplyTo": "",
"references": "",
"attachments": [
{
"id": "att_456",
"filename": "doc.pdf",
"contentType": "application/pdf",
"size": 12345
}
]
},
"timestamp": 1709137000000
}Signature verification
Every webhook delivery includes these headers:
X-AgentMail-Signature-256—v1=<hex>HMAC-SHA256 digest of${timestamp}.${body}X-AgentMail-Timestamp— millisecond timestamp of when the delivery was sent
Verify the timestamp-bound signature in constant time using your webhook secret, and reject requests outside a 5-minute window to prevent replay attacks:
import { createHmac, timingSafeEqual } from "crypto";
const verifyWebhook = (
body: string,
signature256: string | null,
timestamp: string | null,
secret: string,
) => {
if (!signature256?.startsWith("v1=") || !timestamp) return false;
const ts = Number(timestamp);
if (!Number.isFinite(ts) || Math.abs(Date.now() - ts) > 5 * 60 * 1000) {
return false;
}
const expected = createHmac("sha256", secret)
.update(`${timestamp}.${body}`)
.digest("hex");
const provided = signature256.slice(3).toLowerCase();
if (provided.length !== expected.length) return false;
return timingSafeEqual(Buffer.from(provided, "utf8"), Buffer.from(expected, "utf8"));
};
// In your webhook handler:
// const body = await req.text();
// const sig = req.headers.get("x-agentmail-signature-256");
// const ts = req.headers.get("x-agentmail-timestamp");
// if (!verifyWebhook(body, sig, ts, process.env.AGENTMAIL_WEBHOOK_SECRET!)) {
// return new Response("Unauthorized", { status: 401 });
// }Billing & Limits
AgentMail offers straightforward mailbox rentals with transparent volume allowances:
- Free trial: One mailbox is free for 30 days after phone verification (20 sends/day, 50 receives/day, up to 100 sends & 200 receives/mo). Inbound & webhooks included; signup/OTP verification emails unlock with a $5 deposit.
- Rental: $1/mo per active mailbox. $5 minimum deposit into your prepaid wallet (prepaid balance = 5 mailbox-months. covers renewals automatically.).
- Paid Mailbox Limits ($1/mo): 1,000 sends/month and 1,000 receives/month (capped at 200 sends/day and 200 receives/day). Daily limits reset at 00:00 UTC. Contact support if you need custom limits.
- Trial Mailbox Limits: 20 sends/day (up to 100/mo) and 50 receives/day (up to 200/mo). Inbound signup, OTP, and account activation emails are blocked on free trials until a $5 deposit is added.
- Webhooks: Real-time webhooks (up to 5 per mailbox) for all accepted emails.
Real-time outbound protection
Every outbound email is inspected in real time by an automated AI spam and phishing filter before leaving the server. Phishing, credential harvesting, deceptive impersonation, and unsolicited mass spam are immediately blocked with a 400 Bad Request (code SPAM_REJECTED).
/v1/billing/checkoutCreate a Stripe checkout session to top up $5 into your organization's prepaid balance.
Request body (optional)
{
"successUrl": "https://my-app.example.com/billing?status=success",
"cancelUrl": "https://my-app.example.com/billing?status=cancelled"
}Response (200)
{
"data": {
"checkoutUrl": "https://checkout.stripe.com/c/pay/cs_..."
}
}/v1/billing/balanceCheck your organization's prepaid wallet balance.
Response
{
"data": {
"balance": 5.0,
"admin": false,
"trialUsed": true
}
}Organizations
Each organization has one billing user (the creator) and can have additional admins. Balance and accounts belong to the organization, not individual users.
Organizations are managed from the dashboard. By default, each user can create one organization. Contact support@theagentmail.net to create additional organizations.
Account API keys
/v1/accounts/:accountId/api-keysCreate a token scoped to a single account. Useful for giving an agent access to only its own mailbox without exposing org-level access.
Request body
{
"name": "My agent's key" // optional
}Response (201)
{
"data": {
"id": "key_123",
"key": "am_abc123...",
"prefix": "am_abc1",
"name": "My agent's key",
"createdAt": 1709136000000
}
}The full key is only returned once. Store it securely.
Errors
All errors return a JSON object with an error message and code:
{
"error": "Human-readable error message",
"code": "MACHINE_READABLE_CODE"
}SPAM_REJECTEDOutbound message blocked by real-time spam/phishing scan (or RESERVED_ADDRESS on account creation)UNAUTHORIZEDMissing or invalid API key / tokenINSUFFICIENT_BALANCEInsufficient prepaid balance (or ACCOUNT_EXPIRED if mailbox is frozen/expired)FORBIDDENAccount-scoped token accessing org-level endpoint (or PHONE_VERIFICATION_REQUIRED on trial)NOT_FOUNDResource not foundADDRESS_EXISTSEmail address is already in useSEND_LIMIT_REACHEDMonthly or daily (DAILY_SEND_LIMIT_REACHED) send limit exceededINTERNAL_ERRORSomething went wrong on our endRemote MCP Server
Connect Claude Code, Claude Desktop, OpenCode, Cursor, Windsurf, or any Streamable HTTP MCP client directly to https://api.theagentmail.net/mcp — no local bridge or npm install required.
Pass an account-scoped API key to restrict the agent to a single mailbox (get_mailbox, list_messages, get_message, send_email, get_attachment_url, webhook tools), or an org key to also expose list_mailboxes, create_mailbox, and get_balance.
Claude Code (one command)
claude mcp add --transport http agentmail https://api.theagentmail.net/mcp \
--header "Authorization: Bearer am_..."Cursor / OpenCode / MCP JSON config
{
"mcpServers": {
"agentmail": {
"url": "https://api.theagentmail.net/mcp",
"headers": {
"Authorization": "Bearer am_..."
}
}
}
}TypeScript & Python Examples
No SDK package is required. The REST API works out of the box with built-in fetch in TypeScript/Node/Deno/Bun or requests in Python.
Prefer a typed wrapper? The MIT TypeScript client lives directly in github.com/uriva/agentmail/tree/main/sdk.
TypeScript (zero dependencies)
const headers = {
Authorization: `Bearer ${process.env.AGENTMAIL_KEY}`,
"Content-Type": "application/json",
};
// Send an email (account-scoped key)
await fetch("https://api.theagentmail.net/v1/messages", {
method: "POST",
headers,
body: JSON.stringify({
to: ["human@example.com"],
subject: "Hello from my agent",
text: "This email was sent by an AI agent.",
}),
});
// Check inbox
const { data: messages } = await fetch(
"https://api.theagentmail.net/v1/messages",
{ headers },
).then((r) => r.json());
// Register a webhook
await fetch("https://api.theagentmail.net/v1/webhooks", {
method: "POST",
headers,
body: JSON.stringify({ url: "https://my-agent.example.com/inbox" }),
});Python (requests)
import os, requests
HEADERS = {"Authorization": f"Bearer {os.environ['AGENTMAIL_KEY']}"}
# Send an email
requests.post(
"https://api.theagentmail.net/v1/messages",
headers=HEADERS,
json={
"to": ["human@example.com"],
"subject": "Hello from my agent",
"text": "This email was sent by an AI agent.",
},
).raise_for_status()
# List inbox messages
messages = requests.get(
"https://api.theagentmail.net/v1/messages",
headers=HEADERS,
).json()["data"]Agent Skills & llms.txt
Point any AI coding agent (Claude Code, OpenCode, Cursor, OpenClaw, Codex) at https://theagentmail.net/llms.txt with an account-scoped API key and it can immediately send, read, and wire up webhooks without extra docs.
If your agent runs on OpenCode, you can also install the AgentMail skill directly:
opencode skill install agentmail