email
mcp-name: io.github.n24q02m/better-email-mcp
IMAP/SMTP email for AI agents -- read, send, organize, and manage attachments across accounts.
[Mode]
[CI]
[codecov]
[npm]
[Docker]
[License: Apache-2.0]
[TypeScript]
[Node.js]
[IMAP/SMTP]
[semantic-release]
[Renovate]
Sister projects from n24q02m (click to expand)
Table of contents
[Better Email MCP server]
Features
- Multi-account support -- manage 6+ email accounts (Gmail, Outlook, Yahoo, iCloud, Zoho, ProtonMail, custom IMAP)
- App Passwords -- no OAuth2 setup required for most providers; clone and run in 1 minute
- 4 composite tools (plus
help) -- search, read, send, reply, forward, organize, and credential status in single calls
- Auto-discovery -- provider settings detected from email address, custom IMAP host supported
- Thread-aware -- reply/forward maintains In-Reply-To and References headers
- Tiered token optimization -- compressed descriptions + on-demand
help tool + MCP Resources
Install
The server runs in two modes: stdio (default, single-user, credentials from env vars) and HTTP (opt-in, single-user with a bearer token). For stdio, add it to your MCP client config:
The package is @n24q02m/email (formerly @n24q02m/better-email-mcp; old package
receives one final release then freezes). The MCP Registry id stays
io.github.n24q02m/better-email-mcp, and the legacy better-email-mcp command is
kept as an alias of email.
Multiple accounts are comma-separated: [email protected]:pass1,[email protected]:pass2. See Configuration for all env vars, and Remote (HTTP Mode) to run a hosted multi-user server.
Most providers use an App Password (no OAuth setup); Outlook/Hotmail/Live use a bundled OAuth device-code flow in HTTP mode. Settings (IMAP/SMTP host, port) are auto-discovered from the email domain.
Install matrix
Full per-client walkthroughs: docs.n24q02m.com/servers/email/setup/.
CLI
The package ships one binary, email (run via npx @n24q02m/email), also installed under its legacy name better-email-mcp. With no arguments it starts the MCP server over stdio; it also accepts one flag and one subcommand:
auth/logout are only for Outlook/Hotmail/Live addresses -- other providers use an App Password in EMAIL_CREDENTIALS. See Remote (HTTP Mode) for the HTTP config.
Smithery
Published with a Smithery config (smithery.yaml). Smithery runs the server over stdio with no build config required; credentials come from the environment (see Configuration). The start command is:
Documentation
Full docs at docs.n24q02m.com/servers/email/:
- Setup -- install methods for Claude Code, Codex, Gemini CLI, Cursor, Windsurf, mcp.json
Install with AI agent -- paste this to your AI coding agent:
Install MCP server email following the steps at
https://raw.githubusercontent.com/n24q02m/claude-plugins/main/plugins/better-email-mcp/setup-with-agent.md
Tools
Public tool rename
The public send tool is replaced by messages with action: new, reply, or forward.
This follows the MCP N+2 standard: sending is an action in the messages domain, so keeping a
separate send entry would duplicate that domain and add redundant tool-list and help-topic
surface. The old name is removed directly; there is no compatibility alias.
MCP Resources
Comparison
How email stacks up against direct competitors in each pillar:
Remote (HTTP Mode)
Run as a single-user HTTP server, authenticated with a shared bearer token:
Self-Hosting (HTTP Mode)
Single-user mode: one shared bearer token; accounts come from env vars or email auth outlook <address>:
Mint the hash with printf '%s' "$TOKEN" | email token hash; the token is read from stdin, never argv. Clients send the raw token as Authorization: Bearer <token>. Saved Outlook tokens live under /data/.better-email-mcp/ and persist when the /data volume is kept.
Self-Hosting with Docker Compose
The repository ships docker-compose.http.yml, which builds the http image target and
publishes it on host loopback only (127.0.0.1:8082):
The server is then reachable at http://localhost:8082. To serve other machines, put your own TLS reverse proxy on the same host in front of the loopback port. Prebuilt multi-arch images are published to Docker Hub (n24q02m/email)
and GHCR (ghcr.io/n24q02m/email).
Outlook OAuth Device Code
Outlook/Hotmail/Live accounts use OAuth2 device-code. Run email auth outlook <address> once. On first use:
- The CLI prints a device code and a Microsoft login URL
- Open the URL in a browser and enter the code
- Sign in and authorize the app
- Tokens are saved to
~/.better-email-mcp/tokens.json (created with mode 0600 on POSIX). In Docker that path is /data/.better-email-mcp/tokens.json.
OAuth uses the bundled public Azure client (d56f8c71-9f7c-43f4-9934-be29cb6e77b0, Thunderbird-pattern) -- no user-side Azure registration needed.
In stdio mode, Outlook accounts use an App Password instead (Outlook Account Settings → Security → Advanced security options → App passwords).
Configuration
To trust mise configuration automatically, set trusted_config_paths in the user-level config at ~/.config/mise/config.toml; do not add it to this project's .mise.toml.
Multiple Accounts
Custom IMAP Host
Each account can use its own host and port. A non-993 port is treated as
plaintext/STARTTLS -- the usual shape for a local IMAP proxy (for example
email-oauth2-proxy).
Microsoft 365 work/school accounts
A mailbox in a Microsoft 365 organisation -- including one on your own domain --
signs in through Entra ID rather than the consumer directory, and Microsoft
disabled basic auth for Exchange Online in 2024, so an App Password is not an
option. Two settings make it work:
OUTLOOK_TENANT applies to the token refresh as well as the initial sign-in --
refreshing a work/school token against the consumer directory fails with
AADSTS7000012: The grant was obtained for a different tenant.
If the mailbox was consented with a narrower grant (say IMAP but no SMTP), match
it with OUTLOOK_SCOPES so the refresh does not ask for more than was granted.
Search Query Language
Supported Providers
Security
- Credential sanitization -- Passwords never leaked in error messages
- App Passwords -- Uses app-specific passwords, not regular passwords
- Token storage -- Outlook OAuth tokens are written with mode 0600 on POSIX (not enforced on Windows)
- IMAP validation -- Search queries validated before execution
Build from Source
Trust Model
Credentials are single-user: whoever runs the server (or your OS user for stdio) can read them. Storage depends on the deployment mode:
License
Apache-2.0 -- See LICENSE.