mcp-name: io.github.n24q02m/better-email-mcp
IMAP/SMTP email for AI agents -- read, send, organize, and manage attachments across accounts.
Table of contents
- Features
- Install
- CLI
- Smithery
- Documentation
- Tools
- Comparison
- Remote (HTTP Mode)
- Outlook OAuth Device Code (HTTP mode)
- Configuration
- Security
- Build from Source
- Trust Model
- License
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
helptool + 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:
{
"mcpServers": {
"email": {
"command": "npx",
"args": ["--yes", "@n24q02m/email@latest"],
"env": {
"EMAIL_CREDENTIALS": "[email protected]:app-password"
}
}
}
}
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: mcp.n24q02m.com/servers/better-email-mcp/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:
# stdio server (normally launched by your MCP client, not by hand)
EMAIL_CREDENTIALS="[email protected]:app-password" npx @n24q02m/email
# HTTP multi-user server
npx @n24q02m/email --http
# One-off Outlook OAuth device-code sign-in
npx @n24q02m/email auth [email protected]
# Sign out of a single account (or omit the email to clear all)
npx @n24q02m/email logout [email protected]
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:
startCommand:
type: stdio
commandFunction: |-
(config) => ({ command: 'npx', args: ['-y', '@n24q02m/email'] })
Documentation
Full docs at mcp.n24q02m.com/servers/better-email-mcp/:
- 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
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:
{
"mcpServers": {
"email": {
"type": "http",
"headers": { "Authorization": "Bearer <your-token>" },
"url": "https://<your-host>/mcp"
}
}
}
Self-Hosting (HTTP Mode)
Single-user mode: one shared bearer token; accounts come from env vars or email auth outlook <address>:
export EMAIL_MCP_TOKEN_HASH='scrypt$...' # required: the container binds 0.0.0.0 and refuses to start without it
export EMAIL_CREDENTIALS='[email protected]:app-password'
docker run -p 8080:8080 \
-e PORT=8080 \
-e EMAIL_MCP_TOKEN_HASH \
-e EMAIL_CREDENTIALS \
-e HOME=/data \
-v email-data:/data \
n24q02m/email:latest
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):
export EMAIL_MCP_TOKEN_HASH='scrypt$...' # required; see the note above
export EMAIL_CREDENTIALS='[email protected]:app-password'
docker compose -f docker-compose.http.yml up
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
[email protected]:pass1,[email protected]:pass2,[email protected]:pass3
Custom IMAP Host
# Custom hostname (default port 993, implicit TLS)
[email protected]:password:imap.custom.com
# Custom hostname with a custom port
[email protected]:password:imap.custom.com:1993
# Local IMAP proxy -- "localhost" is accepted as a host, even without a dot
[email protected]:password:localhost:1993
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:
# Sign in against the directory that owns the mailbox
OUTLOOK_TENANT=common # or a tenant GUID / verified domain
# Route your own domain to OAuth instead of asking for a password
OUTLOOK_EXTRA_DOMAINS=company.com
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
git clone https://github.com/n24q02m/email.git
cd email
bun install
bun run dev
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.