MCP Email Service
Operate multiple email accounts over IMAP/SMTP through MCP tools for reading, searching, sending, and managing emails, plus local sync/cache analytics and daemon health.
List accounts, folders, unread counts, and test IMAP/SMTP connections.
List and search emails across accounts with filters (unread, date range, sender, subject, attachments) and pagination.
Retrieve full email details, headers, and attachments.
Send new emails, reply (including reply-all), and forward with optional attachments.
Mark emails read/unread, flag/star/important/answered, move between folders, and delete (to trash or permanently), with dry-run options.
Analyze contacts and communication timelines from the local sync cache.
Manage email synchronization: start/stop scheduler, force sync, get status/health/history, search/recent cache, and update sync config.
Inspect daemon connection pool stats, recent activity, and service version.
Support multi-account routing via account_id or per-email account mapping.
Use cache-backed operations (SQLite) for speed and live IMAP/SMTP when needed.
Enables management of Gmail accounts including reading, searching, sending, and organizing emails, with support for attachments, folders, and contact analysis.
Provides workflow automation for email monitoring with AI-powered filtering and multi-platform notifications through n8n workflow templates.
Powers AI-based email filtering, translation, summarization, and intelligent monitoring to identify important emails and generate automated responses.
Sends rich formatted email notifications and alerts to Slack channels with block-based formatting for monitored emails.
Delivers styled email notifications to WeChat Work with color coding for AI-monitored important emails.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@MCP Email Service show me unread emails from the last 24 hours"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
mail-use
Email, as something an AI agent can actually operate. One CLI over Gmail, QQ,
163, Outlook and any IMAP/SMTP box — every command speaks JSON, every destructive
one is dry-run until you pass --confirm.
mail-use code --json # the newest verification code, one live pass
mail-use email recent --format compact --json
mail-use email delete --from newsletter@shop.com --confirm --jsonPart of the *-use family — small tools that each give an agent
hands on one real thing.
Why this and not an IMAP snippet
A stable JSON contract, not scraped text. Every response carries
success: boolean, and failures carryerror_codefrom a fixed set (auth_failed,folder_not_found,imap_error, …). Documented indocs/CLI_JSON_CONTRACT.md.It tells you when it might be wrong. Cached reads report
from_cache,cache_age_secondsandcache_stale, and a snapshot old enough to mean "nothing is syncing" is refused in favour of a live fetch. An empty inbox is never a silent "nothing arrived".Destructive by consent only.
delete/mark/move/sendreturn a dry-run preview — grouped per account and folder, with sample subjects — and change nothing until--confirm.--all-foldersskips Sent/Drafts/Junk/Trash unless asked.Built for token budgets.
--format compactprojects each email to the ten fields worth scanning (~30% smaller than the full shape),--with-previewfolds a body snippet into the list call, and batchshowreuses one IMAP connection.Fast enough to call in a loop. A persistent daemon pools IMAP connections and syncs to local SQLite in the background: five sequential
email listcalls go from 25s to 0.83s. See the table below.MCP too.
mail-use mcp config --jsonprints a paste-ready entry; the server exposes 16 tools with the same dry-run defaults.
Renamed from Mailbox to mail-use. The command is now
mail-use;mailboxstill works as an alias, and your config in~/.config/mailboxis untouched.
Supported providers
163 / 126 · QQ · Gmail · Outlook / Hotmail · any custom IMAP+SMTP server.
Search behaves differently per provider and the CLI says so: Gmail searches bodies
server-side via X-GM-RAW, while QQ/163/Outlook have broken IMAP TEXT search, so
--query falls back to matching subject + sender only. Use --from / --subject
there for predictable results.
Related MCP server: Email SMTP/IMAP MCP Server
Install
One line, no npm, no Node
curl -fsSL https://raw.githubusercontent.com/leeguooooo/mail-use/main/install.sh | sh
mail-use --helpDownloads the prebuilt binary for your platform (macOS arm64/x64, Linux x64/arm64) from the
latest GitHub Release, verifies its
checksum, and installs to ~/.local/bin. Pin a version with MAIL_USE_VERSION=v2.11.2, or
change the dir with MAIL_USE_INSTALL_DIR=.... A missing .sha256 aborts the install
(MAIL_USE_INSECURE=1 overrides; a mismatch is always fatal). Each tarball also carries
signed build provenance: gh attestation verify mail-use-<target>.tar.gz --repo leeguooooo/mail-use.
The installer also drops a mailbox symlink next to it, so scripts written against the old
name keep working.
There is no npm package. Distribution is GitHub Release binaries only — that keeps
releases free of NPM_TOKEN and 2FA prompts, and keeps install free of a Node toolchain.
The pre-rename @leeguoo/mailbox-cli packages on npm are frozen and no longer updated.
Upgrading
mail-use upgrade --check # is there a newer release? (`mail-use 3.3.1 -> 3.3.2`)
mail-use upgrade --check --json # the same check as JSON: name, current, latest, update_available, skills, install_channel, checked_only
mail-use upgrade # (--json only changes the output format) CLI only: download, verify sha256, check the new binary's version, swap atomically, restart the daemon
mail-use upgrade --skills # the same, then refresh this tool's own skill copies (skill-only when the CLI is current)
mail-use upgrade --tag v3.1.0 # pin an exact release (also the way to roll back)Exit code 0 means the command worked (an update being available is not an error); 2
means the check, the download or the verification failed (the installed binary is left
as it was); 1 means it refused because Homebrew, npm or a source checkout owns this
install (it prints that manager's command instead), or a skill could not be refreshed.
A plain upgrade only lists the skill copies it finds, with the command that would refresh
each. upgrade --skills refreshes them: a Claude Code plugin
(claude plugin update mail-use@leeguooooo-plugins, or printed if claude isn't on PATH),
a git checkout linked into ~/.agents/skills, ~/.claude/skills or ~/.codex/skills
(git pull --ff-only, never forced), or a copied folder from npx skills add (it prints
npx skills update mail-use for you to run).
Any other command checks for a new release at most once a day (cached in
${XDG_CACHE_HOME:-~/.cache}/mail-use/update-check.json, 2 s timeout, failures silent) and,
when one exists, prints a single line to stderr — stdout stays clean JSON:
mail-use 3.3.2 is available (you have 3.3.1). Upgrade: mail-use upgrade. Set CI,
MAIL_USE_NO_UPDATE_CHECK or USE_NO_UPDATE_CHECK to turn it off.
When the daemon is running it notices new releases for you: one unauthenticated GET to
the GitHub releases API per day (MAILBOX_UPDATE_CHECK_HOURS, 0 disables), surfaced as
update in mail-use daemon status --json. It only ever reports — it never downloads
or installs anything.
upgrade is never automatic and never runs on its own: a tool that silently replaces
its own executable is a supply-chain surprise, not a convenience. It refuses to install
a tarball whose published .sha256 is missing or doesn't match, or whose binary does not
report the requested version, and refuses to run at all from a Homebrew, npm or dev-checkout
install. Re-running the curl … install.sh | sh
line does the same job.
As an AI Skill (Claude Code / Cursor / etc.)
# Project scope — installs into ./.claude/skills/mail-use (or ./.cursor/skills/...):
npx skills add leeguooooo/mail-use --skill mail-use
# User scope — installs into ~/.claude/skills/mail-use:
npx skills add leeguooooo/mail-use --skill mail-use -gThe skill assumes the CLI is on PATH (install via the curl … install.sh | sh above).
For the biggest speedup also run mail-use daemon install once.
MCP server (Claude Desktop / Code / Cursor)
mail-use mcp config --json # prints a paste-ready mcpServers entryFrom source (development)
pnpm install
pnpm test
# build a local platform binary into dist/mail-use
pnpm build:binaryIf a test run is interrupted (editor task killed, agent session closed), its
Vitest workers can be left behind and hold memory. Check with
pgrep -fl vitest and kill what remains.
Configure accounts
mkdir -p ~/.config/mailbox
cp examples/accounts.example.json ~/.config/mailbox/auth.jsonConfig locations:
Credentials:
~/.config/mailbox/auth.jsonOther settings:
~/.config/mailbox/config.toml
Apple Mail, both ways
Agents use mail-use, people use Apple Mail; both talk to the same server, so an account only has to be set up once:
mail-use apple-mail status # which mailboxes each side has
mail-use apple-mail # mail-use → Apple Mail: opens System Settings on the profile, click Install
mail-use apple-mail import # Apple Mail → mail-use: paste one app password / authorization code per mailbox
mail-use account add # neither side has it yet: start hereApple Mail keeps its passwords to itself (and Gmail added through Google sign-in has none), so importing needs one authorization code per mailbox; macOS only installs profiles through System Settings, so exporting needs one click. Mailboxes already in Apple Mail are skipped, so nothing gets duplicated. Step-by-step guide (Chinese), where to get each provider's code, and FAQ: docs/guides/apple-mail.md.
Common commands
# CLI help
mail-use --help
# newest verification code across all accounts, one live pass
mail-use code --json
# list accounts
mail-use account list --json
# list unread emails (cache by default; --from filters cache-side)
mail-use email list --unread-only --limit 20 --json
mail-use email list --account-id my_account_id --from "newsletter" --json
# show one email (response includes list_unsubscribe when the header is set)
mail-use email show 123456 --account-id my_account_id --json
# mark read (use --dry-run to validate first)
mail-use email mark 123456 --read --account-id my_account_id --folder INBOX --dry-run --json
mail-use email mark 123456 --read --account-id my_account_id --folder INBOX --confirm --json
# delete
mail-use email delete 123456 --account-id my_account_id --folder INBOX --confirm --json
# bulk mutate by sender or subject (no UID list needed)
mail-use email mark --from "support@npmjs.com" --read --confirm --account-id my_account_id --json
mail-use email delete --from "newsletter" --account-id my_account_id --json # dry-run preview
mail-use email delete --subject "[ad]" --account-id my_account_id --confirm --jsonCache + sync
Cache DB default:
~/.local/share/mailbox/email_sync.dbListing uses cache by default where possible. Add
--liveto force IMAP.
mail-use sync status --json
mail-use sync force --json
mail-use sync init
mail-use sync daemonPersistent daemon (5-30× faster CLI calls)
Each one-shot invocation otherwise spends 1-3s on TCP+TLS+IMAP LOGIN. With the daemon
running, calls reuse pooled connections and a background SQLite sync means email list
usually doesn't touch IMAP at all.
The curl … install.sh | sh installer sets this up for you when accounts are already
configured (MAIL_USE_NO_DAEMON=1 opts out). Otherwise:
mail-use daemon install # autostart at login (macOS launchd / Linux systemd-user)
mail-use daemon status --json
mail-use daemon reload # drop pooled connections after editing auth.jsonMeasured on Gmail INBOX, M2 MacBook over residential WAN:
Operation | No daemon | Daemon ( | Daemon (cached) |
Single | 5.0s | 1.0s | 0.17s |
| 5.0s | 0.85s | n/a |
5 sequential | 25s | 5.3s | 0.83s |
3 parallel | ~15s | 2.7s | 0.88s |
Resource footprint (many agent sessions on one machine)
The daemon is one process per user, shared by every agent session through a Unix socket — so more sessions do not mean more IMAP connections. Measured idle on macOS with 3 accounts connected:
Idle CPU | ~0.15% |
Idle RSS | 3-15 MB |
Connections | max 3 per account ( |
12 concurrent calls | 1.6s wall clock, pool stayed at 1 connection per account |
Knobs, if the defaults do not suit you:
Env | Default | Effect |
|
| Max concurrent IMAP connections per account |
|
| Close connections idle this long ( |
|
| Connections per account kept warm through reaping |
| unset |
|
|
| Daemon's passive update check ( |
| unset | Any value turns off the CLI's daily "new version" notice |
AI usage guide
Mail classification belongs to the calling AI. mail-use cleanup --limit 50 --json
returns live metadata, body previews and gids for review; use --offset for the
next page and email show <gid...> for full content. The AI selects specific gids
and executes them with email move, mark, flag or delete. cleanup and
inbox never classify or choose actions, and legacy category cleanup is rejected.
If you're integrating this CLI into an AI agent, start here:
docs/AI_SKILL_MAIL_USE.md
OpenClaw integration
This repo includes an OpenClaw skill at skills/mail-use/SKILL.md.
OpenClaw loads skills from:
<workspace>/skills~/.openclaw/skills
Quick link helper (symlink into ~/.openclaw/skills):
./scripts/link_openclaw_skill.shForce replace an existing link:
./scripts/link_openclaw_skill.sh --forceTo use this repo without copying files, add the repo skills directory to
skills.load.extraDirs in ~/.openclaw/openclaw.json:
{
"skills": {
"load": {
"extraDirs": [
"/path/to/mcp-email-service/skills"
]
}
}
}OpenClaw handles channel delivery and scheduling; mail-use returns structured JSON outputs and optional text summaries.
Verify OpenClaw picked up the skill:
openclaw skills list --eligible
openclaw skills checkThe *-use family
Small, composable CLIs that give an AI agent hands on one real thing. Same shape
everywhere: curl … install.sh | sh to install, npx skills add leeguooooo/<name>
to teach your agent, JSON on stdout.
Repo | Gives your agent |
A real browser — logged-in sessions, forms, scraping, screenshots | |
Email — read, search, send, triage across Gmail / QQ / 163 / any IMAP | |
A real iPhone — tap, type, screenshot, pull on-device data | |
WeChat on macOS — send messages, query contacts and history | |
Discord — messages, channels, forums, webhooks (REST-only, Rust) | |
Many logged-in accounts per site — capture, switch, apply sessions | |
Your personal profile, safely — fill signup / KYC / checkout forms | |
Bitwarden / Vaultwarden — headless passkey (FIDO2) login | |
Your ChatGPT subscription as a coding-agent backend — no API key | |
The macOS desktop itself | |
Read-only PixCake probing — snapshot / diff / SQLite inspection |
Contract
docs/CLI_JSON_CONTRACT.md
Built by leeguooooo — field notes on AI agents, reverse engineering & Cloudflare Workers at blog.misonote.com · follow on X @leeguooooo
Author
Built by 郭立 (Guo Li / leeguoo) — leeguoo.com · GitHub · X · more tools in the *-use family.
Available Tools
29 toolsanalyze_contactsA
Analyze contact frequency and communication patterns using the local sync database. Works only after emails have been synchronized to the cache.
Inputs: account_id, days, limit, group_by.
batch_delete_emailsC
Delete multiple emails (move to trash or permanently delete)
Inputs: email_ids (required), folder, permanent, trash_folder, +2 more.
batch_mark_readC
Mark multiple emails as read
Inputs: email_ids (required), folder, account_id.
check_connectionB
Test email server connections (IMAP and SMTP) for all configured accounts using stored credentials.
Inputs: no named parameters.
delete_emailA
Delete a single email (move to trash or permanently delete). account_id optional but recommended.
Inputs: email_id (required), folder, permanent, trash_folder, +1 more.
delete_emailsA
Delete one or more emails (move to trash or permanently delete). Provide account_id or email_accounts mapping so each UID can be routed to the right mailbox.
Inputs: email_ids (required), folder, permanent, trash_folder, +3 more.
flag_emailA
Flag/star or unflag an email. Runs against the live mailbox—account_id recommended to avoid cross-account lookups.
Inputs: email_id (required), flag_type (required), set_flag, folder, +1 more.
forward_emailC
Forward an email to other recipients using SMTP credentials of the selected account.
Inputs: email_id (required), to (required), body, folder, +2 more.
get_connection_pool_statsA
Get IMAP connection pool statistics from the local sync service, including connection reuse rate and active connections (no remote calls).
Inputs: no named parameters.
get_contact_timelineA
Get communication timeline with a specific contact from the local sync cache (no live IMAP).
Inputs: contact_email (required), account_id, days.
get_email_attachmentsA
Extract attachments from an email by downloading them over IMAP. Requires a reachable mailbox and may incur network latency.
Inputs: email_id (required), folder, account_id.
get_email_detailA
Get detailed content of a specific email including body and attachments. Requires IMAP connectivity to download the latest message content.
Inputs: email_id (required), folder, account_id.
get_email_headersA
Fetch only email headers (From, To, Subject, Date, Message-ID, etc.) without downloading the body. account_id recommended so the UID lookup hits the right mailbox.
Inputs: email_id (required), folder, account_id, headers.
get_recent_activityB
Return recent sync activity/health per account based on local cache data.
Inputs: account_id, include_stats.
get_sync_healthA
Get sync health status for all accounts or a specific account based on cached sync metrics (no live IMAP).
Inputs: account_id.
get_sync_historyB
Get synchronization history for all accounts or a specific account within specified hours from the local sync logs.
Inputs: account_id, hours.
get_versionB
Get MCP Email Service version and git commit
Inputs: no named parameters.
list_accountsB
List all configured email accounts
Inputs: no named parameters.
list_emailsA
List emails from inbox (supports multi-account). UIDs are scoped to each account—pass account_id for deterministic follow-up actions. Performs live IMAP fetch; failures usually indicate network or credential issues.
Inputs: limit, offset, unread_only, folder, +3 more.
list_foldersB
List all email folders/labels in the account (IMAP). Provide account_id to target a specific mailbox.
Inputs: account_id.
list_unread_foldersA
List folders with unread counts per configured account. Requires live IMAP connectivity; returns empty list when the mailbox cannot be reached.
Inputs: account_id, include_empty.
mark_email_readA
Mark a single email as read (account_id optional but recommended to avoid cross-account lookup).
Inputs: email_id (required), folder, account_id.
mark_emailsA
Mark one or more emails as read or unread. Pass account_id when operating within a single account, or provide email_accounts mapping for mixed-account batches.
Inputs: email_ids (required), mark_as (required), folder, account_id, +2 more.
mark_email_unreadB
Mark a single email as unread (account_id optional but recommended).
Inputs: email_id (required), folder, account_id.
move_emails_to_folderB
Move emails to a different folder. Requires IMAP access; pass account_id (or use per-email mapping in mark/delete first) so UIDs match the correct account.
Inputs: email_ids (required), target_folder (required), source_folder, account_id.
reply_emailA
Reply to an email (preserves thread). Requires SMTP access for the originating account.
Inputs: email_id (required), body (required), reply_all, folder, +3 more.
search_emailsB
Search emails with various criteria across all accounts or specific account. Returned UIDs must be used with the same account; specify account_id for precise targeting.
Inputs: query, search_in, date_from, date_to, +6 more.
send_emailB
Send a new email with optional attachments via SMTP. Ensure the account has SMTP server configuration and valid credentials.
Inputs: to (required), subject (required), body (required), cc, +4 more.
sync_emailsB
Unified email synchronization tool: start/stop scheduler, force sync, get status, search cache, manage config (action: start|stop|force|status|search|recent|config). Operates on the local sync service and databases.
Inputs: action, full_sync, account_id, query, +2 more.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 29 tools
The tool set has clear functional distinctions for core email operations like sending, replying, and listing, but there is significant overlap in batch operations (e.g., delete_email, delete_emails, batch_delete_emails) and read/unread marking tools (mark_email_read, mark_email_unread, mark_emails, batch_mark_read), which could cause confusion. Descriptions help clarify some differences, but the boundaries are not always sharp.
Most tools follow a consistent verb_noun naming pattern (e.g., list_emails, send_email, search_emails), with clear and descriptive names. There are minor deviations like get_version and check_connection, which use 'get' and 'check' instead of more specific verbs, but overall the naming is predictable and readable across the set.
With 29 tools, the count feels excessive for an email service, leading to redundancy and potential confusion. While email management can involve many operations, the set includes multiple tools for similar actions (e.g., three deletion tools), suggesting it could be streamlined without losing functionality, making it borderline heavy for the domain.
The tool set provides comprehensive coverage for email management, including CRUD operations (send, list, delete), synchronization (sync_emails), folder management (list_folders, move_emails_to_folder), contact analysis (analyze_contacts, get_contact_timeline), and health monitoring (get_sync_health, check_connection). There are no obvious gaps, and agents can handle full email workflows effectively.
Maintenance
Related MCP Connectors
One inbox for all your addresses: your AI agent reads, sorts, drafts and sends with your permission.
Your AI reads and watches every inbox, and replies like your mail app once you confirm each email.
Email for AI agents: read, search and send from your Gmail, Outlook, Yahoo, iCloud or IMAP inbox.
AI-native email for businesses, developers, and AI agents.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceEnables comprehensive email management through IMAP/SMTP protocols with tools for searching, organizing, moving, flagging, and sending emails across various email providers. Features safe preview mode for destructive operations and supports multiple email providers including Gmail, Outlook, and Chinese email services.6 npmMIT
- AlicenseAqualityFmaintenanceEnables email management through SMTP and IMAP protocols with support for sending emails with attachments, searching and filtering messages, replying/forwarding with threading, organizing mailboxes, and managing multiple email accounts.5737 npmMIT
- AlicenseNot gradedqualityDmaintenanceEnables AI assistants to manage multiple email accounts with secure credentials, local full-text search, thread-aware replies, and automation.7 npmMIT
- AlicenseNot gradedqualityDmaintenanceEnables unified email management across Gmail, Outlook, iCloud, and IMAP providers with tools for search, send, organize, and batch operations via natural language.MIT