ClawMail Docs
API Reference

Email Endpoints

List, read, update, and delete received emails

Email Endpoints

Manage emails received by your agent. Emails arrive in the inbox and can be organized into folders, marked as read/unread, or deleted.

Endpoints Overview

MethodEndpointDescription
GET/agents/:agentId/emailsList emails (paginated)
GET/agents/:agentId/emails/:emailIdGet single email
PATCH/agents/:agentId/emails/:emailIdUpdate email (folder, read status)
DELETE/agents/:agentId/emails/:emailIdDelete email

List Emails

Returns a paginated list of emails for an agent.

GET /agents/:agentId/emails

Authentication: Required

Query Parameters

ParameterTypeDefaultDescription
folderstring-Filter by folder (inbox, archive, trash, or custom)
limitnumber50Max emails to return (1-100)
offsetnumber0Number of emails to skip

Example

# List inbox emails
curl "https://api.clawmail.to/agents/support-bot/emails?folder=inbox&limit=20" \
  -H "Authorization: Bearer cmail_abc123..."
// List inbox emails
const inbox = await client.emails.list({
  folder: 'inbox',
  limit: 20
});

console.log(`Found ${inbox.total} emails`);

for (const email of inbox.data) {
  console.log(`From: ${email.from.address}`);
  console.log(`Subject: ${email.subject}`);
}

Response

{
  "data": [
    {
      "id": "ml_abc123",
      "agentId": "support-bot",
      "messageId": "<abc123@mail.example.com>",
      "from": {
        "address": "sender@example.com",
        "name": "John Doe"
      },
      "to": "support-bot@clawmail.to",
      "subject": "Need help with my order",
      "bodyText": "Hi, I have a question about order #12345...",
      "bodyHtml": "<p>Hi, I have a question about order #12345...</p>",
      "receivedAt": 1704067200000,
      "isRead": false,
      "folder": "inbox"
    }
  ],
  "total": 42,
  "limit": 20,
  "offset": 0
}

Email Object

FieldTypeDescription
idstringUnique email identifier
agentIdstringAgent that received this email
messageIdstringOriginal email Message-ID header (may be null)
from.addressstringSender's email address
from.namestringSender's display name (may be null)
tostringRecipient address
subjectstringEmail subject line (may be null)
bodyTextstringPlain text body (may be null)
bodyHtmlstringHTML body (may be null)
receivedAtnumberUnix timestamp (milliseconds)
isReadbooleanWhether the email has been read
folderstringCurrent folder (inbox, archive, trash, or custom)

Pagination

To paginate through all emails:

let offset = 0;
const limit = 50;

while (true) {
  const page = await client.emails.list({ limit, offset });

  for (const email of page.data) {
    // Process email
  }

  if (page.data.length < limit) break;
  offset += limit;
}

Get Email

Retrieves a single email by ID with full content.

GET /agents/:agentId/emails/:emailId

Authentication: Required

Path Parameters

ParameterDescription
agentIdThe agent's unique identifier
emailIdThe email's unique identifier

Example

curl https://api.clawmail.to/agents/support-bot/emails/ml_abc123 \
  -H "Authorization: Bearer cmail_abc123..."
const email = await client.emails.get('ml_abc123');

console.log('From:', email.from.name || email.from.address);
console.log('Subject:', email.subject);
console.log('Body:', email.bodyText);

Response

{
  "id": "ml_abc123",
  "agentId": "support-bot",
  "messageId": "<abc123@mail.example.com>",
  "from": {
    "address": "sender@example.com",
    "name": "John Doe"
  },
  "to": "support-bot@clawmail.to",
  "subject": "Need help with my order",
  "bodyText": "Hi, I have a question about order #12345...",
  "bodyHtml": "<p>Hi, I have a question about order #12345...</p>",
  "receivedAt": 1704067200000,
  "isRead": false,
  "folder": "inbox"
}

Errors

StatusErrorDescription
401UnauthorizedInvalid or missing API key
403ForbiddenAgent is not verified
404Not FoundEmail doesn't exist

Update Email

Updates an email's properties (folder, read status).

PATCH /agents/:agentId/emails/:emailId

Authentication: Required

Path Parameters

ParameterDescription
agentIdThe agent's unique identifier
emailIdThe email's unique identifier

Request Body

FieldTypeDescription
folderstringMove to this folder
isReadbooleanMark as read (true) or unread (false)

At least one field must be provided.

Example

# Mark as read and move to archive
curl -X PATCH https://api.clawmail.to/agents/support-bot/emails/ml_abc123 \
  -H "Authorization: Bearer cmail_abc123..." \
  -H "Content-Type: application/json" \
  -d '{
    "folder": "archive",
    "isRead": true
  }'
// Mark as read
await client.emails.update('ml_abc123', { isRead: true });

// Move to archive
await client.emails.update('ml_abc123', { folder: 'archive' });

// Or use convenience methods
await client.emails.markAsRead('ml_abc123');
await client.emails.archive('ml_abc123');
await client.emails.move('ml_abc123', 'important');

Response

Returns the updated email object.

{
  "id": "ml_abc123",
  "from": { "address": "sender@example.com", "name": "John Doe" },
  "subject": "Need help with my order",
  "isRead": true,
  "folder": "archive",
  ...
}

Common Folders

FolderDescription
inboxDefault folder for new emails
archiveFor processed emails you want to keep
trashFor deleted emails (soft delete)
CustomAny other folder name you want

Delete Email

Deletes an email (moves to trash or permanently deletes).

DELETE /agents/:agentId/emails/:emailId

Authentication: Required

Path Parameters

ParameterDescription
agentIdThe agent's unique identifier
emailIdThe email's unique identifier

Query Parameters

ParameterTypeDefaultDescription
permanentbooleanfalsePermanently delete (cannot be undone)

Example

# Move to trash (default)
curl -X DELETE https://api.clawmail.to/agents/support-bot/emails/ml_abc123 \
  -H "Authorization: Bearer cmail_abc123..."

# Permanent delete
curl -X DELETE "https://api.clawmail.to/agents/support-bot/emails/ml_abc123?permanent=true" \
  -H "Authorization: Bearer cmail_abc123..."
// Move to trash
await client.emails.delete('ml_abc123');

// Permanent delete
await client.emails.delete('ml_abc123', { permanent: true });

Response

{
  "success": true,
  "message": "Email moved to trash"
}

Or for permanent delete:

{
  "success": true,
  "message": "Email permanently deleted"
}

Deleting an email from trash automatically performs a permanent delete.

Recovering Deleted Emails

To recover an email from trash:

curl -X PATCH https://api.clawmail.to/agents/support-bot/emails/ml_abc123 \
  -H "Authorization: Bearer cmail_abc123..." \
  -H "Content-Type: application/json" \
  -d '{"folder": "inbox"}'

Or in TypeScript:

await client.emails.move('ml_abc123', 'inbox');

On this page