AgenticMail
OfficialDomain mode uses Cloudflare for automatic DNS configuration (MX, SPF, DKIM, DMARC, tunnel CNAME), Cloudflare Tunnel for secure inbound traffic, and Cloudflare Email Worker for routing. Supports domain purchase via Cloudflare Registrar.
Relay mode allows agents to send and receive internet email through a Gmail account, using a +alias address for each agent. Setup takes minutes and leverages Gmail's SMTP/IMAP for mail delivery.
Google Voice integration gives agents a real phone number for sending and receiving SMS, extracting verification codes, and handling phone calls. Includes a setup wizard to handle Gmail and Voice account matching.
๐ AgenticMail
The first platform to give AI agents real email addresses and phone numbers. Send and receive email, SMS, and verification codes โ all programmatically.
๐ Research Paper
Structured RPC vs. Text-Based Sub-Agent Orchestration โ A comparative analysis of inter-agent communication paradigms. Demonstrates why AgenticMail's call_agent achieves 53ร faster response times than conventional sub-agent spawning, and introduces the concept of the Conversational Fallacy in multi-agent AI systems. [PDF] [Source]
AgenticMail is a self-hosted communication platform purpose-built for AI agents. It runs a local Stalwart mail server via Docker, integrates Google Voice for SMS/phone access, exposes a REST API with 75+ endpoints, and works with any MCP-compatible AI client and OpenClaw via plugin. Each agent gets its own email address, phone number, inbox, and API key.
Table of Contents
Why ๐ AgenticMail?
AI agents need to communicate with the real world. Email is the universal communication protocol โ every person and business has an email address. AgenticMail bridges the gap between AI agents and email by providing:
Isolated mailboxes โ each agent has its own email address, inbox, and credentials. Agents can't read each other's mail.
Internet email connectivity โ two gateway modes to send/receive real email (Gmail relay or custom domain with DKIM/SPF/DMARC).
Security guardrails โ outbound scanning prevents agents from leaking API keys, passwords, or PII. Blocked emails require human approval.
Agent collaboration โ agents can email each other, assign tasks, and make synchronous RPC calls.
SMS / Phone number access โ integrate Google Voice for SMS receive/send, verification code extraction, and phone number access for AI agents.
Smart orchestration โ
call_agentreplaces basic sub-agent spawning with auto mode detection, dynamic timeouts, runtime tool discovery, and async execution for long-running tasks.Tool integrations โ 62 MCP tools for any AI client, 63 OpenClaw tools, and a 44-command interactive shell.
Self-updating โ
agenticmail updatechecks npm, verifies OpenClaw compatibility, and updates both packages automatically.
Features
Email Operations
Send email with text, HTML, attachments, CC/BCC, reply-to, and custom headers
Receive email via IMAP with real-time SSE event streaming (IMAP IDLE)
Reply and forward with proper In-Reply-To and References headers for threading
Search by sender, subject, body text, date range, read/unread status
Folders โ create, list, move messages between folders
Batch operations โ mark read/unread, delete, move multiple messages at once
Drafts โ save, edit, and send draft emails
Templates โ reusable email templates with variable substitution
Scheduled sending โ queue emails for future delivery
Signatures โ per-agent email signatures
Tags โ label and categorize messages
Contacts โ manage address book per agent
Multi-Agent
Account management โ create, list, delete agents with unique email addresses
Agent-to-agent email โ agents can email each other directly via
@localhostTask system โ assign tasks to agents, claim, submit results, track status
RPC calls โ synchronous agent-to-agent calls with timeout (long-poll + SSE notification)
Agent directory โ discover other agents by name
Gateway (Internet Email)
Relay mode (beginner) โ use your existing Gmail or Outlook as a relay. Emails appear as
you+agentname@gmail.com. Setup takes 2 minutes.Domain mode (advanced) โ custom domain via Cloudflare. Agents send from
agent@yourdomain.comwith full DKIM signing, SPF, and DMARC records.Automatic DNS configuration (MX, SPF, DKIM TXT, DMARC, tunnel CNAME)
Cloudflare Tunnel for secure inbound traffic without exposing ports
Cloudflare Email Worker for Email Routing (catch-all โ worker โ AgenticMail)
Optional Gmail SMTP outbound relay for residential IPs without PTR records
Domain purchase via Cloudflare Registrar
DNS backup before any modifications
Automatic
@domainemail alias for all existing agents
Security
Outbound guard โ scans every outgoing email for sensitive data patterns:
API keys and tokens (AWS, OpenAI, Stripe, GitHub, etc.)
Passwords and credentials
Private keys (SSH, PGP, RSA)
PII patterns (SSN, credit card numbers)
Internal URLs and configuration data
Blocked emails are held for human-only approval (agents cannot self-approve)
Spam filter โ rule-based scoring engine for inbound email:
Categories: phishing, scam, malware, commercial spam, social engineering, lottery scam
Configurable threshold (default: 40)
Skips internal agent-to-agent emails
Runs on both relay inbound and SSE event streams
Human-only approval flow โ when an agent's email is blocked:
The agent is informed the email was blocked and told to notify their owner
The owner receives a notification email with full blocked email content, warnings, and pending ID
Only the master key holder can approve or reject (
POST /mail/pending/:id/approve)Agents can list and view their own pending emails but cannot approve or reject them
System prompt guidelines instruct agents to inform their owner and wait, never attempt to bypass
DKIM/SPF/DMARC โ automatic DNS setup in domain mode for email authentication
Rate limiting โ configurable per-endpoint rate limits
SMS / Phone Number Access
Google Voice integration โ give agents a real phone number via Google Voice
Direct Voice web reading (primary, instant) โ reads SMS directly from voice.google.com via browser
Email forwarding (fallback) โ Google Voice forwards SMS to email, agent auto-detects and records them during relay polling
Separate Gmail polling โ for users whose GV Gmail differs from relay email, runs a dedicated IMAP poll
Verification codes โ automatic extraction of OTP/verification codes from SMS (4-8 digit, alphanumeric, Google G-codes)
Send SMS โ record outbound messages, send via Google Voice web automation
Smart setup wizard โ validates Gmail/GV email matching, warns about mismatches, collects separate credentials when needed
Smart Orchestration (call_agent)
Auto mode detection โ reads task complexity, picks light/standard/full mode automatically
Dynamic timeouts โ 60s for quick tasks, 5+ minutes for deep research, 1 hour for async
Runtime tool discovery โ probes host config for available tools instead of static deny lists
Async execution โ long-running tasks run independently, auto-compact context, email results when done
Structured RPC โ sub-agents return JSON, not raw text
Integrations
MCP server โ 62 tools for any MCP-compatible AI client
OpenClaw plugin โ 63 tools with skill definition and system prompt guidelines
REST API โ 75+ endpoints, OpenAPI-style, Bearer token auth
SSE events โ real-time inbox notifications via Server-Sent Events
Interactive CLI โ 44 shell commands with arrow key navigation, body previews, retry logic
Self-updating โ
agenticmail updateor/updatein shell, with OpenClaw compatibility check
Architecture
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ AgenticMail โ
โ โ
AI Client โMCPโ> โ @agenticmail/mcp (62 tools, stdio transport) โ
โ โ โ
OpenClaw โโโโโ> โ @agenticmail/openclaw (63 tools, plugin) โ
โ โ โ
HTTP clientsโโ> โ โผ โ
โ @agenticmail/api (Express, 75+ endpoints) โ
โ โโโ Authentication (master key + agent keys) โ
โ โโโ Rate limiting (per-endpoint) โ
โ โโโ SSE streaming (real-time inbox events) โ
โ โโโ Spam filter + Outbound guard โ
โ โ โ
โ โผ โ
โ @agenticmail/core (SDK layer) โ
โ โโโ AccountManager (CRUD agents in Stalwart) โ
โ โโโ MailSender (SMTP, nodemailer) โ
โ โโโ MailReceiver (IMAP, imapflow) โ
โ โโโ InboxWatcher (IMAP IDLE โ events) โ
โ โโโ GatewayManager (relay + domain routing) โ
โ โ โโโ RelayGateway (Gmail/Outlook) โ
โ โ โโโ CloudflareClient (DNS, tunnels, etc) โ
โ โ โโโ TunnelManager (cloudflared) โ
โ โ โโโ DNSConfigurator (MX, SPF, DKIM) โ
โ โ โโโ DomainPurchaser (Registrar API) โ
โ โโโ StalwartAdmin (mail server management) โ
โ โโโ EmailSearchIndex (FTS5 full-text search) โ
โ โโโ Storage (SQLite + migrations) โ
โ โ โ
โ โผ โ
โ Stalwart Mail Server (Docker container) โ
โ โโโ SMTP (port 587) โ submission โ
โ โโโ SMTP (port 25) โ inbound delivery โ
โ โโโ IMAP (port 143) โ mailbox access โ
โ โโโ HTTP (port 8080) โ admin API โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ โ
โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ
โผ โผ
Relay Mode Domain Mode
โโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโ
โ Gmail / Outlook โ โ Cloudflare โ
โ IMAP polling โ โ โโโ DNS zone โ
โ SMTP relay โ โ โโโ Tunnel โ
โ Sub-addressing โ โ โโโ Email Routing โ
โ (+agent@gmail) โ โ โโโ Email Worker โ
โโโโโโโโโโโโโโโโโโโโ โ โโโ Registrar โ
โโโโโโโโโโโโโโโโโโโโโโโโData Flow
Sending email (relay mode):
Agent calls
POST /mail/sendwith recipient, subject, bodyAPI runs outbound guard scan โ if sensitive data found, email is blocked and owner notified
GatewayManager detects external recipient โ routes to RelayGateway
RelayGateway sends via Gmail SMTP as
owner+agentname@gmail.comReply-To set to agent's relay address so replies route back
Sending email (domain mode):
Agent calls
POST /mail/sendOutbound guard scan runs
GatewayManager rewrites
agent@localhostโagent@yourdomain.comEmail submitted to local Stalwart via SMTP (port 587)
Stalwart signs with DKIM, resolves MX, delivers directly (or via Gmail relay)
Receiving email (relay mode):
RelayGateway polls Gmail IMAP every 30 seconds for new messages
New email detected โ parsed โ spam scored
If not spam, delivered to agent's local Stalwart mailbox via SMTP
X-AgenticMail-Relay: inboundheader added for identificationInboxWatcher (IMAP IDLE) fires SSE event to connected clients
Receiving email (domain mode):
External sender sends to
agent@yourdomain.comCloudflare Email Routing catches all โ routes to Email Worker
Worker reads raw RFC822 message, base64-encodes, POSTs to
/api/agenticmail/mail/inboundInbound endpoint validates secret, parses email, delivers to agent's mailbox
InboxWatcher fires SSE event
Quick Start
Prerequisites
Install
npm install -g @agenticmail/cliSetup
# 1. Start the mail server
docker compose up -d
# 2. Run the setup wizard (creates config, initializes database, creates first agent)
agenticmail setup
# 3. Start the API server + interactive shell
agenticmail startThe setup wizard will:
Check Docker is running and Stalwart is healthy
Generate a master API key
Create the SQLite database with all required tables
Create your first AI agent with its own email address and API key
Optionally configure a gateway (relay or domain mode) for internet email
Send your first email (programmatic)
import { AgenticMailClient } from 'agenticmail';
const client = new AgenticMailClient({
apiUrl: 'http://127.0.0.1:3100',
apiKey: 'ak_your_agent_api_key',
});
// Send an email
await client.send({
to: 'colleague@example.com',
subject: 'Hello from my AI agent',
text: 'This email was sent by an AI agent using AgenticMail.',
});
// Check inbox
const inbox = await client.listInbox(10);
for (const msg of inbox) {
console.log(`${msg.from} โ ${msg.subject}`);
}
// Read a specific email
const email = await client.readMessage(inbox[0].uid);
console.log(email.text);Send your first email (CLI)
agenticmail> /send
To: someone@example.com
Subject: Test email
Body: Hello from the AgenticMail shell!
Email sent! Message ID: <abc123@localhost>Send your first email (curl)
curl -X POST http://127.0.0.1:3100/api/agenticmail/mail/send \
-H "Authorization: Bearer ak_your_agent_key" \
-H "Content-Type: application/json" \
-d '{
"to": "someone@example.com",
"subject": "Hello",
"text": "Sent via the AgenticMail API."
}'CLI Commands
AgenticMail includes a full CLI for managing your server. All commands are available via agenticmail <command> or npx @agenticmail/cli@latest <command>.
Core Commands
Command | Description |
| Start the server (runs setup first if not initialized). Opens the interactive shell after startup. This is the default command โ just run |
| Run the setup wizard. Walks you through system checks, account creation, service startup, email connection (Gmail/Outlook/custom domain), phone number setup, and OpenClaw integration. Safe to re-run โ won't overwrite existing config. |
| Start the server and open the interactive shell. Ensures Docker is running, Stalwart is up, and the API server is reachable. Automatically installs the auto-start service if not already set up. |
| Stop the server. Kills the background API server process. If auto-start is enabled, it will restart on next boot. Use |
| Show what's running. Displays the status of Docker, Stalwart, the API server, email connection, and auto-start service. |
Integration Commands
Command | Description |
| Set up AgenticMail for OpenClaw. Starts infrastructure, creates an agent, configures the OpenClaw plugin, enables agent auto-spawn via hooks, and restarts the OpenClaw gateway. |
Service Management (Auto-Start)
AgenticMail installs a system service so it automatically starts when your computer boots. On macOS this is a LaunchAgent; on Linux it's a systemd user service.
Command | Description |
| Show auto-start status. Displays whether the service is installed and running. |
| Install the auto-start service. AgenticMail will start automatically on boot. The startup script waits up to 10 minutes for Docker to be ready, then checks that Stalwart is running (starts it if needed), then launches the API server. |
| Remove the auto-start service. AgenticMail will no longer start on boot. |
| Reinstall the service. Use this after config changes or updates to refresh the service file. |
What happens on reboot:
Your computer starts โ Docker Desktop launches (its own auto-start)
Stalwart mail server starts (
restart: unless-stoppedin Docker)AgenticMail startup script waits for Docker to be ready (up to 10 min)
Script verifies Stalwart is running (auto-starts it if Docker restarted without it)
API server starts and begins accepting requests
If the API server crashes, the system service automatically restarts it.
Maintenance Commands
Command | Description |
| Update to the latest version. Checks npm for a new version, updates the CLI and OpenClaw plugin, and restarts the OpenClaw gateway if applicable. |
| Show available commands. |
Logs
Server logs are stored in ~/.agenticmail/logs/:
server.logโ API server stdoutserver.err.logโ API server stderrstartup.logโ Boot sequence log (Docker wait times, Stalwart checks)
Gateway Modes
AgenticMail supports two modes for sending/receiving real internet email:
Relay Mode (Beginner-Friendly)
Use your existing Gmail or Outlook account as a relay. No domain purchase needed. Setup takes under 2 minutes.
How it works:
Outbound: emails sent via your Gmail/Outlook SMTP as
you+agentname@gmail.comInbound: AgenticMail polls your Gmail/Outlook IMAP for new messages addressed to
you+agentname@gmail.comand delivers them to the agent's local mailboxGmail's
+sub-addressing routes replies back to the right agent
Setup:
# In the interactive shell:
agenticmail> /relay
# Or via API:
curl -X POST http://127.0.0.1:3100/api/agenticmail/gateway/relay \
-H "Authorization: Bearer mk_your_master_key" \
-H "Content-Type: application/json" \
-d '{
"provider": "gmail",
"email": "you@gmail.com",
"password": "xxxx xxxx xxxx xxxx"
}'Requirements:
Gmail: App password (not your regular password)
Outlook: App password from Microsoft account security settings
Domain Mode (Advanced)
Full custom domain with Cloudflare. Agents send from agent@yourdomain.com with proper email authentication.
What gets configured automatically:
Cloudflare DNS zone creation
MX records pointing to Cloudflare Email Routing
SPF record (
v=spf1 include:_spf.mx.cloudflare.net ~all)DKIM key generation and TXT record
DMARC record (
v=DMARC1; p=quarantine)Cloudflare Tunnel (CNAME record, ingress rules)
Cloudflare Email Worker deployment (catches all inbound email)
Catch-all Email Routing rule โ Worker โ AgenticMail inbound endpoint
Stalwart hostname, DKIM signing, domain principal
@domainemail aliases for all existing agentsOptional: Gmail SMTP outbound relay, domain purchase
Setup:
curl -X POST http://127.0.0.1:3100/api/agenticmail/gateway/domain \
-H "Authorization: Bearer mk_your_master_key" \
-H "Content-Type: application/json" \
-d '{
"cloudflareToken": "your_cf_api_token",
"cloudflareAccountId": "your_cf_account_id",
"domain": "yourdomain.com",
"gmailRelay": {
"email": "you@gmail.com",
"appPassword": "xxxx xxxx xxxx xxxx"
}
}'Cloudflare API token permissions needed:
Zone: DNS (Edit), Email Routing (Edit)
Account: Cloudflare Tunnel (Edit), Workers Scripts (Edit), Registrar (Edit โ only if purchasing domains)
Packages
This is a TypeScript monorepo with 5 packages:
Package | Description | Install |
CLI, setup wizard, interactive shell. Install this to get started. |
| |
Core SDK โ accounts, SMTP/IMAP, gateway, spam filter, outbound guard, storage |
| |
Express REST API server with 75+ endpoints |
| |
MCP server with 62 tools for any MCP-compatible AI client |
| |
OpenClaw plugin with 63 tools and skill definition |
|
Dependency graph:
agenticmail (CLI) โโ> @agenticmail/api โโ> @agenticmail/core
@agenticmail/mcp (standalone โ HTTP calls to API)
@agenticmail/openclaw (standalone โ HTTP calls to API)API Overview
All endpoints are under /api/agenticmail. Authentication via Authorization: Bearer <key> header.
Two key types:
Master key (
mk_...) โ full admin access (create/delete agents, approve blocked emails, gateway config)Agent key (
ak_...) โ scoped to one agent (read own inbox, send email, manage own drafts/contacts/etc.)
Key Endpoints
Method | Path | Auth | Description |
|
| Agent | Send email (text, HTML, attachments) |
|
| Agent | List inbox messages (paginated) |
|
| Agent | Inbox with body previews |
|
| Agent | Read full email with headers and attachments |
|
| Agent | Search by from, subject, body, date |
|
| Agent | Move to folder |
|
| Agent | Report as spam |
|
| Agent | List all folders |
|
| Both | List blocked outbound emails |
|
| Master | Approve blocked email |
|
| Master | Reject blocked email |
Accounts | |||
|
| Master | Create new agent |
|
| Master | List all agents with metadata |
|
| Agent | Get own agent info |
|
| Master | Delete agent (with email archival) |
|
| Both | Agent discovery directory |
Events | |||
|
| Agent | SSE stream โ new email with route metadata, flags, expunge events |
Gateway | |||
|
| Both | Current gateway mode and health |
|
| Master | Configure relay mode |
|
| Master | Configure domain mode |
|
| Both | Send a test email |
Tasks | |||
|
| Both | Assign task to another agent |
|
| Both | Synchronous agent-to-agent RPC (long-poll) |
|
| Agent | List tasks assigned to me |
|
| Agent | Claim a pending task |
|
| Agent | Submit task result |
Plus endpoints for drafts, contacts, tags, rules, signatures, templates, scheduled emails, spam management, batch operations, domains, and agent deletion/cleanup.
See the API package README for complete endpoint documentation.
MCP Integration
The MCP server exposes 62 tools to any MCP-compatible AI client via stdio transport.
Setup
Add to your MCP client configuration (e.g., .mcp.json or project settings):
{
"mcpServers": {
"agenticmail": {
"command": "npx",
"args": ["agenticmail-mcp"],
"env": {
"AGENTICMAIL_API_URL": "http://127.0.0.1:3100",
"AGENTICMAIL_API_KEY": "ak_your_agent_key"
}
}
}
}Desktop Clients
For desktop AI applications, add the same configuration to your app's MCP config file (check your app's documentation for the file location).
What your AI can do
Once connected, your AI can:
"Check my inbox" โ
list_inbox"Send an email to john@example.com about the project update" โ
send_email"Reply to that last email saying thanks" โ
reply_email"Search for emails from Sarah about the budget" โ
search_emails"Create a draft response to the client" โ
manage_drafts"What tasks are assigned to me?" โ
check_tasks"Ask the research agent to look up competitor pricing" โ
call_agent
See the MCP package README for the full tool list.
OpenClaw Integration
Already have OpenClaw? Two steps:
# Step 1 โ Install AgenticMail globally and run the setup wizard
npm install -g @agenticmail/cli && agenticmail setup# Step 2 โ Connect AgenticMail to your OpenClaw instance
agenticmail openclawThat's it. The global install gives you the agenticmail command. The openclaw command will start the mail server, create an agent, and merge the plugin config into your openclaw.json automatically. Your OpenClaw agent now has its own email address.
Manual Configuration
If you prefer to configure manually, add to ~/.openclaw/openclaw.json:
{
"plugins": {
"agenticmail": {
"enabled": true,
"config": {
"apiUrl": "http://127.0.0.1:3100",
"apiKey": "ak_your_agent_key",
"masterKey": "mk_your_master_key"
}
}
}
}The plugin survives OpenClaw updates โ plugin configuration lives in user config (~/.openclaw/openclaw.json), not in the OpenClaw source directory.
Chat with Your AI Agent
Use /chat in the AgenticMail shell to talk directly to your OpenClaw agent in real-time:
โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ โฏ what's the weather in NYC? โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
You ๐ค
โญโโโโโโโโโโโโโโโฎ
โ what's the โ
โ weather in โ
โ NYC? โ
โฐโโโโโโโโโโโโโโโฏ
๐ Fola
โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ Currently 42ยฐF and cloudy in NYC. โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏWebSocket connection to OpenClaw gateway with Ed25519 device auth
Bubble-style chat UI with markdown rendering
Animated thinking indicator with elapsed timer
Multi-line input (Enter sends,
\+ Enter for new lines)
Smart Sub-Agent Spawning
The call_agent tool intelligently spawns sub-agents:
Auto mode detection โ light (simple tasks), standard (web research), full (multi-agent coordination)
Dynamic timeouts โ 60s / 180s / 300s based on complexity
Dynamic tool discovery โ probes OpenClaw config at runtime instead of static deny lists
Async mode โ
call_agent(async=true)for long-running tasks. The caller polls/tasks/assignedfor completion; the assigned agent emails the result back to the caller when it has email capability enabled. In a localhost-only / no-relay setup the result still lands in the caller's local mailbox, so check/mail/inboxif you don't see an SMTP delivery.Web search fallback โ uses DuckDuckGo when Brave API isn't configured
See the OpenClaw package README for the full tool list.
Interactive Shell
The CLI includes a full-featured interactive shell with 44 commands:
agenticmail> /inbox
โ
1 john@example.com Project Update 2m ago
2 sarah@example.com Re: Budget Review 1h ago
3 notifications@github.com [repo] New issue #42 3h ago
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Page 1/3 โ [โ] prev [โ] next [v] toggle previews [Esc] back
Use โโ arrow keys to select, Enter to read inlineKey features:
Arrow key navigation with cursor selection
Body preview toggle (press
v)Inline email reading (press
Enter)Unread markers (
โ)3-retry input validation on all prompts
Paginated views with
โ/โnavigation
Command Reference
Email: /inbox /send /read /reply /forward /search /delete /save
/thread /unread /archive /trash
Organize: /folders /contacts /drafts /signature /templates /schedule /tag
Agents: /agents /switch /deleteagent /deletions
Security: /spam /rules /pending
Gateway: /relay /digest /setup /status /openclaw
System: /help /clear /exitSecurity
Outbound Guard
Every outgoing email is scanned before sending. The guard detects:
Category | Examples |
API keys |
|
Credentials |
|
Private keys |
|
PII | Social security numbers, credit card patterns |
Internal data | Localhost URLs, internal IPs, config file contents |
When sensitive data is detected:
Email is blocked and saved to the
pending_outboundtableAgent receives a response explaining what was blocked and why, with instructions to inform their owner
Owner (master key holder) is notified via email with the full blocked email content, security warnings, recipient, subject, and pending ID
Owner approves or rejects via the master key API (
POST /mail/pending/:id/approveor/reject) or by replying to the notification emailAgents cannot approve or reject their own blocked emails โ the approve/reject endpoints require the master key
Agents can only list and view their pending emails to check approval status
MCP and OpenClaw tools enforce this by rejecting approve/reject actions with a message directing agents to inform their owner
System prompt guidelines (OpenClaw) instruct agents to never attempt self-approval or rewrite emails to bypass detection
Spam Filter
Inbound emails are scored against rule-based patterns:
Category | Score Range | Examples |
Phishing | 10-30 | Fake login pages, urgency language, spoofed senders |
Scam | 15-25 | Nigerian prince, lottery winner, inheritance schemes |
Malware | 20-30 | Suspicious attachments, executable links |
Commercial | 5-15 | Unsolicited marketing, unsubscribe-heavy emails |
Social engineering | 10-20 | Impersonation, authority pressure |
Emails scoring >= 40 (configurable) are moved to Spam folder
Emails scoring 20-39 get a warning flag
Internal agent-to-agent emails skip spam filtering entirely
Relay-rewritten emails (
@localhostfrom, external replyTo) are always treated as external
Authentication
Master key โ full admin access, required for agent creation/deletion, gateway config, email approval
Agent API keys โ scoped per-agent, can only access own inbox and send from own address
Inbound webhook secret โ authenticates Cloudflare Email Worker requests to the inbound endpoint
Configuration
Environment Variables
# === Required ===
AGENTICMAIL_MASTER_KEY=mk_your_key # Master API key (generate: openssl rand -hex 32)
# === Stalwart Mail Server ===
STALWART_ADMIN_USER=admin # Stalwart admin username
STALWART_ADMIN_PASSWORD=changeme # Stalwart admin password
STALWART_URL=http://localhost:8080 # Stalwart HTTP admin URL
# === SMTP/IMAP (local Stalwart) ===
SMTP_HOST=localhost # SMTP host
SMTP_PORT=587 # SMTP submission port
IMAP_HOST=localhost # IMAP host
IMAP_PORT=143 # IMAP port
# === Optional ===
AGENTICMAIL_API_PORT=3100 # API server port (default: 3100)
AGENTICMAIL_DATA_DIR=~/.agenticmail # Data directory for SQLite DB and config
# === Gateway: Relay Mode ===
RELAY_PROVIDER=gmail # gmail or outlook
RELAY_EMAIL=you@gmail.com # Your email address
RELAY_PASSWORD=xxxx xxxx xxxx xxxx # App password
# === Gateway: Domain Mode ===
CLOUDFLARE_API_TOKEN=your_token # Cloudflare API token
CLOUDFLARE_ACCOUNT_ID=your_account_id # Cloudflare account ID
AGENTICMAIL_DOMAIN=yourdomain.com # Your domain
AGENTICMAIL_INBOUND_SECRET=your_secret # Shared secret for Email Worker
# === Gmail SMTP Relay (domain mode outbound) ===
GMAIL_RELAY_EMAIL=you@gmail.com # Gmail address for outbound relay
GMAIL_RELAY_APP_PASSWORD=xxxx xxxx xxxx # Gmail app password
# === Debug ===
# AGENTICMAIL_DEBUG=1 # Enable verbose per-message loggingDocker Compose
# docker-compose.yml (included in repo)
services:
stalwart:
image: stalwartlabs/stalwart:latest
container_name: agenticmail-stalwart
ports:
- "8080:8080" # HTTP Admin + JMAP
- "587:587" # SMTP Submission
- "143:143" # IMAP
- "25:25" # SMTP Inbound
volumes:
- stalwart-data:/opt/stalwart
- ~/.agenticmail/stalwart.toml:/opt/stalwart/etc/stalwart.toml:ro
restart: unless-stoppedSQLite Database
AgenticMail stores all state in a SQLite database at ~/.agenticmail/agenticmail.db:
agentsโ agent accounts (name, email, API key, metadata)gateway_configโ relay or domain mode configurationpending_outboundโ blocked emails awaiting approvaldelivered_messagesโ deduplication tracking for inbound relayspam_logโ spam scoring historyagent_tasksโ inter-agent task assignmentsemail_rulesโ per-agent email filtering rulescontacts,drafts,signatures,templates,scheduled_emails,tags
Development
Setup
git clone https://github.com/agenticmail/agenticmail.git
cd agenticmail
npm install
docker compose up -d
npm run build
npm testProject Structure
agenticmail/
โโโ agenticmail/ # CLI facade package (npm: agenticmail)
โ โโโ src/
โ โโโ cli.ts # CLI entry point (setup, start, status)
โ โโโ shell.ts # Interactive REPL (44 commands)
โ โโโ index.ts # Re-exports from @agenticmail/core
โโโ packages/
โ โโโ core/ # @agenticmail/core
โ โ โโโ src/
โ โ โโโ accounts/ # Agent CRUD, roles, deletion
โ โ โโโ mail/ # Sender, receiver, parser, spam filter, outbound guard
โ โ โโโ inbox/ # IMAP IDLE watcher
โ โ โโโ gateway/ # Relay, Cloudflare, DNS, tunnel, domain purchase
โ โ โโโ stalwart/ # Stalwart admin API client
โ โ โโโ storage/ # SQLite database, migrations, search index
โ โ โโโ domain/ # Domain management
โ โ โโโ setup/ # Dependency checker, installer
โ โโโ api/ # @agenticmail/api
โ โ โโโ src/
โ โ โโโ app.ts # Express app factory
โ โ โโโ routes/ # 8 route modules (mail, accounts, events, etc.)
โ โ โโโ middleware/ # Auth, rate limiting, error handling
โ โโโ mcp/ # @agenticmail/mcp
โ โ โโโ src/
โ โ โโโ index.ts # MCP server entry (stdio transport)
โ โ โโโ tools.ts # 63 tool definitions and handlers
โ โ โโโ resources.ts
โ โโโ openclaw/ # @agenticmail/openclaw
โ โโโ index.ts # Plugin entry, system prompt
โ โโโ src/tools.ts # 63 tool definitions and handlers
โ โโโ skill/ # SKILL.md, reference docs, scripts
โโโ docker-compose.yml # Stalwart mail server
โโโ .env.example # Environment variable template
โโโ package.json # Workspace rootBuild Commands
# Build all packages
npm run build
# Build a single package
cd packages/core && npx tsup src/index.ts --format esm --dts --clean
# Run all tests
npm test
# Run tests for a specific package
cd packages/core && npx vitest runPublish to npm
Publish in dependency order:
cd packages/core && npm publish
cd packages/api && npm publish
cd packages/mcp && npm publish
cd packages/openclaw && npm publish
cd agenticmail && npm publishAll scoped packages have "publishConfig": { "access": "public" } configured.
See CONTRIBUTING.md for development guidelines.
Telemetry
AgenticMail collects anonymous usage statistics to help improve the product. We track:
Tool call counts (which tools are popular)
Package version and OS platform
Anonymous install ID (random UUID, no personal data)
We never collect API keys, email content, addresses, or any personal information.
Opt out by setting the environment variable:
export AGENTICMAIL_TELEMETRY=0
# or
export DO_NOT_TRACK=1Telemetry is also automatically disabled in CI environments.
Troubleshooting
OpenClaw plugin ID mismatch warning
plugin id mismatch (manifest uses "agenticmail", entry hints "openclaw")This is harmless. OpenClaw infers the plugin ID from the npm package name (@agenticmail/openclaw) but the manifest declares "id": "agenticmail". The plugin loads and works correctly.
OpenClaw plugin path not found
If OpenClaw reports the plugin path not found, update plugins.load.paths in ~/.openclaw/openclaw.json to point to the correct location:
npm prefix -g
# Plugin is at: <prefix>/lib/node_modules/@agenticmail/openclawagenticmail: command not found
Use npx agenticmail for one-off usage, or install globally with npm install -g @agenticmail/cli.
License
MIT - Ope Olatunji (@ope-olatunji)
Maintenance
Latest Blog Posts
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/agenticmail/agenticmail'
If you have feedback or need assistance with the MCP directory API, please join our Discord server