Discover MCPs & agents
Loading MCPs and agents…
Loading MCPs and agents…
Secure IMAP/SMTP/EWS/Graph API MCP server in Rust — Microsoft 365, Hotmail, Gmail, Zoho, OAuth2, multi-account
Jump to setup instructionsNo tool list is on record. This does not mean the server has no tools. Tools were not run.
No setup evidence yet No matching config or report on record. This does not mean the server is incompatible.
Same catalog task: Security & auth.
GitHub MCP proxy server — bridges the official @modelcontextprotocol/server-github with Alfe OAuth credentials (Pattern A multi-account)
Same catalog task: Security & auth.
GitHub MCP proxy server — bridges the official @modelcontextprotocol/server-github with Alfe OAuth credentials (Pattern A multi-account)
Same catalog task: Security & auth.
XSUAA / OAuth authentication + BTP principal propagation for Model Context Protocol (MCP) servers built on Express and @modelcontextprotocol/sdk.
Fetched from the repository for this visit.
Production-ready email MCP server for AI agents
IMAP + SMTP + EWS + Microsoft Graph API — built in Rust
Most email MCP servers only do IMAP reads. This one does everything: read, search, send, reply, forward, bulk operations, Microsoft Graph API, and Exchange Web Services — with real OAuth2, multi-account, and multi-provider support. Written in Rust for speed and safety.
For hosts that own the OAuth2 sign-in and launch mail-mcp once per request.
Existing configurations behave as before.
MAIL_OAUTH2_<ID>_ACCESS_TOKEN takes a host-managed access token. It is
used as is for IMAP and SMTP XOAUTH2 and never refreshed, so the host keeps
the refresh token (which Microsoft rotates on every refresh) and passes a
fresh access token on each launch. With it, CLIENT_ID and REFRESH_TOKEN
are optional. An expired or rejected token is an auth_failed error that
names the variable; the token never appears in logs or errors. Environment
or .env only, not a TOML field.CLIENT_SECRET is optional. Missing or empty means a public client: the
refresh request sends no client_secret, as none already did.auth_failed, with the server
text kept, for example Gmail's [ALERT] Application-specific password required. These used to be reported as internal errors.imap_verify_account now says "Account verification failed" in its summary
when the check fails, instead of always reporting success.RUST_LOG=trace no longer writes IMAP passwords or tokens to the log.
async-imap traces every command on the wire, so it is now capped at debug
unless RUST_LOG names async_imap explicitly.Two opt-out settings for hosts that launch mail-mcp as an embedded
component with a fixed environment. Without them, behavior is unchanged.
MAIL_UPDATE_CHECK=false skips the startup release check. By default
the server asks the GitHub releases API for the latest version (waiting at
most 2 seconds) and adds an update notice to its instructions. Hosts that
pin the version can now turn that request off.MAIL_DOTENV=false turns off legacy .env discovery. The .env file
is searched in the working directory and every parent. With this set in the
process environment, no .env is read and none of its variables are
exported, so a stray file cannot add accounts or settings.Both accept false, 0 or off; a value that is not a boolean is a startup
error.
ProtectHome=true (and
similar sandboxes) stopped with could not read config file ~/.mail-mcp/config.toml: Permission denied. Startup now treats an
inaccessible default location like a missing file, prints a warning, and
runs from the environment as earlier releases did. Set
MAIL_CONFIG_FILE=none to skip the check. An explicit --config or
MAIL_CONFIG_FILE path that cannot be read is still an error.graph_send_message now honors MAIL_SMTP_WRITE_ENABLED. It was the
only send tool that skipped the check, so an account with a Microsoft
token carrying Mail.Send could send mail with sending turned off. If you
rely on that setting to keep an agent read-only or drafts-only, upgrade.
A test now checks that every send tool refuses when it is off.
(#45, reported by jtron9k)mail-mcp config init and mail-mcp accounts add
store accounts in ~/.mail-mcp/config.toml, outside the MCP client's JSON.
List, edit, remove, and run read-only connection tests from the CLI.
Start with guided setup.
Environment variables and .env keep working as before, and extra
arguments in an MCP client entry are ignored with a warning, as they were.
(#40, by felipefdl)cargo audit advisory that
has a fix. Tools, their names and their annotations are unchanged.
(#42, by tordable)imap_search_messages and imap_search_all_mailboxes
now fetch the headers of a whole result page with one UID FETCH instead
of one per message. On high-latency servers a 50-message page went from
20-40 s to 3-9 s, and searching every mailbox is about twice as fast.
Results are unchanged.
(#44, by tdabasinskas)readOnlyHint,
destructiveHint, idempotentHint and openWorldHint. Clients that use
them can run the 14 read-only tools without asking each time. Sends,
moves and other changes are marked as writes, and deletes, flag changes,
draft_update and draft_send as destructive.
(#43, by tdabasinskas)RUST_LOG=info. At that
level the rmcp library logged every JSON-RPC response in full, which with
the HTTP transport put message subjects and bodies in the server log (the
journal, for a systemd service). When RUST_LOG sets a global level of
info or more verbose, rmcp is now capped at warn unless RUST_LOG
names it (for example RUST_LOG=info,rmcp=info while debugging). The
stdio transport did not log responses, and with RUST_LOG unset nothing
changes. If you run v0.6.0 or earlier over HTTP, set
RUST_LOG=info,rmcp=warn.https://outlook.office365.com/EWS.AccessAsUser.All with AADSTS70011
(invalid_scope). The Quickstart uses
https://outlook.office.com/EWS.AccessAsUser.All. Existing EWS tokens keep
working; this only matters when getting a new one.Nothing changes for an existing install unless you opt in.
mail-mcp-update; run it to move to the latest release in place.
Homebrew installs keep updating with brew upgrade.MAIL_OAUTH2_TOKEN_STORE to a file
path to also keep it across restarts (written 0600, never fatal if it
cannot be written). Changing the refresh token in your config always wins
over a stored one.body_text and body_html are separate fields" rule now also
appear on the send tools and body fields, for MCP gateways that do not
forward the server instructions. See
Running behind an MCP gateway
for what else changes when mail-mcp sits behind a gateway.draft_create, draft_update, draft_send,
draft_delete, draft_list) closing
#3 and
#17. An agent can
save a message in the account's own Drafts folder, revise it, and send it
later, so a person can review it in their mail client first. The same five
tools work on every backend: IMAP + SMTP, Exchange Web Services and
Microsoft Graph, picked per account (EWS config, else Graph config, else
IMAP). list_all_accounts reports the backend as drafts_with.MAIL_DRAFTS_ENABLED (default false). It is
independent of MAIL_IMAP_WRITE_ENABLED: every operation on an existing
draft_id first checks that the target really is a draft (IMAP Drafts
folder, EWS IsDraft, Graph isDraft), so enabling drafts never grants
move or delete on other mail. draft_send also requires
MAIL_SMTP_WRITE_ENABLED.Mail.ReadWrite scope for drafts; see
account setup. The EWS attachment flow
(CreateItem with SaveOnly, then CreateAttachment) follows the approach
proposed by @verdelyi in
#14.imap_search_all_mailboxes by
@tdabasinskas in
#35. Runs one search
in every selectable mailbox of an account and returns the newest matches,
each labelled with its mailbox. Built for providers without an "All Mail"
folder (iCloud), where one conversation is spread over INBOX, Sent Messages
and project folders. The work is spread over MAIL_IMAP_SEARCH_CONCURRENCY
connections (default 4, clamped to 1..=8); a mailbox that fails is
reported and does not abort the search. Scope it with include_mailboxes /
exclude_mailboxes.imap_search_messages takes a new thread_message_id criterion that
matches a message and every message whose In-Reply-To or References
carries it, so an agent can pull a whole conversation in one search.imap_list_mailboxes cap is now configurable and visible by
@tdabasinskas in
#33. The tool used to
silently drop everything past 200 mailboxes — on accounts with more folders
(e.g. 217 on iCloud), folders like Sent Messages simply never appeared.
The cap is now set with MAIL_IMAP_MAX_MAILBOXES (default 200, clamped to
1..=10000), and the response carries two additive fields, total and
truncated, so clients can always tell a capped list from a complete one.
Nothing changes unless the variable is set.MAIL_MCP_TRANSPORT=http to serve MCP streamable HTTP (stateless) instead
of stdio — useful for running the server on another machine behind an MCP
gateway. Binds to 127.0.0.1:8000 at /mcp by default, configurable via
MAIL_MCP_HTTP_HOST / MAIL_MCP_HTTP_PORT / MAIL_MCP_HTTP_PATH, with
graceful shutdown on SIGINT/SIGTERM. The endpoint has no built-in
authentication — keep it on loopback or behind an authenticating gateway;
see docs/advanced-configuration.md#remote-http-transport. stdio remains
the default: nothing changes unless the variable is set.Community release — both changes came from external contributors. Thank you!
MAIL_ATTACHMENT_UPLOAD_DIR — confine outbound file_path
attachments by @mjones-PL in
#31, closing
#11. Without a
restriction, send tools would read any file the server process can access —
a prompt-injected model could exfiltrate SSH keys or .env files as
attachments. Set this variable to a directory and every file_path is
canonicalized (.. and symlinks resolved) and must land inside it; missing
and out-of-scope files return the same error so the check cannot probe for
file existence. Opt-in: when unset, behavior is unchanged. See
docs/security.md#outbound-attachment-scope.FROM_EMAIL validation no longer rejects dotless internal hosts
by @arwack in
#30. Addresses the
v0.4.13 upgrade caveat: noreply@localhost / alerts@intranet style
addresses on corporate internal relays are accepted again, while the real
typo checks (multiple @, whitespace, empty local part) remain. If you held
the v0.4.13 upgrade because of this, v0.4.14 is safe.effective_from() helper + FROM_EMAIL startup validation by
@arwack in
#29 — the follow-up
to their #19. The from_email → user fallback now lives in one place
(SmtpAccountConfig::effective_from()), and MAIL_SMTP_<ID>_FROM_EMAIL is
validated when the server starts instead of failing on the first send.FROM_EMAIL
(multiple @, whitespace, empty local part, or a domain without a dot) now
prevents the server from starting, for all accounts. Note that dotless
domains such as user@localhost or alerts@intranet are currently rejected
too; if you use an internal relay address like that, hold the upgrade — a
follow-up relaxing the dot rule is under discussion in #29.Community release — both changes came from external contributors. Thank you!
Sent → Sent Messages
on iCloud / [Gmail]/Sent Mail on Gmail, Trash → Deleted Messages, and
so on, multi-language) in search, copy, and move. Raw message fetches now use
BODY.PEEK[], so reading a message through the MCP no longer sets \Seen
as a side effect — with a BODY[] fallback for servers that reject PEEK
(the deprecated RFC822 item, removed in #23, stays out). Validated against
a real iCloud mailbox by the author; includes alias-resolution tests and
iCloud setup docs.scratch
runtime image — 16.9 MB, down from 25.5 MB — verified to respond to MCP
initialize/tools-list over stdio. The toolchain pin was bumped to
Rust 1.90 (the codebase's let-chains require >= 1.88).Community bugfix release — both fixes came from external contributors. Thank you!
\Seen
flag introduced in v0.4.10 was sent without the RFC 3501 parenthesized
flag-list syntax (APPEND "Sent" \Seen … instead of APPEND "Sent" (\Seen) …),
because async-imap interpolates the flags argument verbatim. Strict servers
rejected the APPEND and the sent copy was lost — while the tool still reported
status: ok. Flags are now normalized before hitting the wire, and
smtp_send_message / smtp_reply_message / smtp_forward_message responses
include a new saved_to_sent field (true/false, or null when saving is
disabled) so callers can detect archival failures.
@tordable diagnosed and fixed the same root
cause concurrently in #24.RFC822 item, which iCloud accepts but leaves
unpopulated. Fetches now use the IMAP4rev1 BODY[] item — same \Seen
semantics, works everywhere — with a mock-server regression test pinning the
wire format.Community release — all three changes came from external contributors. Thank you!
ID command after authentication whenever the server
advertises the ID capability. Includes mock-server regression tests and
NetEase setup docs in docs/account-setup.md.MAIL_SMTP_<ID>_FROM_EMAIL — sender address override by
@arwack in
#19. For shared/group
mailboxes where SMTP authenticates with a personal account but the From
address should be the group address. Applies to send, reply (including
reply-all self-address detection) and forward; falls back to _USER when
unset.\Seen by
@ray-of-darkness in
#9. Copies the MCP
appends to the Sent folder after SMTP send no longer show up as unread.imap_get_attachment — download a single attachment to disk.
Until now the only ways to reach attachment bytes were imap_get_message
(which returns attachment metadata and optional extracted PDF text, never
the binary) and imap_get_message_raw (capped at 1 MB and base64-encoded
into the response). A 7 MB email with X-ray images could not be retrieved at
all — over the cap, and dumping it into the response would blow up the model's
context anyway.imap_get_attachment with the message_id plus a
selector — either part_id (the value imap_get_message reports for each
attachment) or filename. The server fetches the full message (no size cap on
the server side), extracts and decodes just that one part, and writes it to
disk, returning { file_path, filename, content_type, part_id, size_bytes }.
The binary never enters the response, so context stays small. The saved path
feeds straight into a local reader (e.g. an image-description tool or a PDF
reader).output_dir argument if given, else the
MAIL_ATTACHMENT_DOWNLOAD_DIR environment variable, else the system temp dir.
Filenames are sanitized (basename only, control characters stripped) to
prevent path traversal, and prefixed with the message UID and part id to avoid
collisions.include_base64: true to also get the bytes
in the response, but only when the attachment is at most max_inline_bytes
(default 256 KiB). Off by default.SAVE_SENT is now per-account with a provider-aware default.
Previously, saving a copy of outgoing mail to the Sent folder via IMAP
APPEND was controlled by a single global flag, MAIL_SMTP_SAVE_SENT. The
problem: providers that already save sent mail server-side (Gmail,
Zoho) ended up with two identical copies in Sent, while a generic SMTP
server or Office 365 (which do not auto-save on SMTP submission) lost
the copy entirely when the flag was false.smtp.gmail.com): saves server-side and deduplicates by
Message-ID → the MCP does not append (false).smtp.zoho.com): saves server-side but does not
deduplicate → the MCP does not append (false), avoiding the
duplicate.true), or the sent copy would be lost.MAIL_SMTP_<ID>_SAVE_SENT=true|false takes
priority over everything. The global MAIL_SMTP_SAVE_SENT still works as a
coarse override (wins over the provider default, loses to the per-account
override).| Provider | Auto-saves server-side | MCP default |
|---|---|---|
| Gmail | Yes (with dedupe) | false |
| Zoho | Yes (no dedupe) | false |
| Office 365 (SMTP) | No | true |
| Generic SMTP / relays | No | true |
graph_send_message silently dropped attachments on
threaded replies. When called with in_reply_to + attachments, the
createReply → PATCH → send flow included the attachments in the PATCH
against /me/messages/{id}. Microsoft Graph treats Message.attachments
as a navigation property and silently discards the field on PATCH
(2xx response, no error), so the message went out as single-part
text/html with no file. The MCP returned status: ok and the caller
assumed success. Invisible data loss.send_via_reply(), attachments are now uploaded one by one
to POST /me/messages/{draft_id}/attachments between the PATCH and the
send. Files < 3 MB go inline (JSON with base64 contentBytes); files
≥ 3 MB use createUploadSession with 4 MB chunked PUTs. The attachments
field was removed from the PatchDraftRequest struct so the regression
cannot be reintroduced by a type-correct edit.send_via_sendmail (new
messages without in_reply_to) uses POST /me/sendMail with attachments
inline in the JSON — Graph DOES accept the field on that endpoint and never
dropped it. That path is untouched.patch_draft_request_never_serializes_attachments
fails if anyone re-adds the field to the struct.BUG_GRAPH_ATTACHMENTS.md at the repo root documents the
full reproduction, root cause, and the empirical evidence behind the fix.</body_text><parameter name="body_html"> markup into the
recipient's inbox. v0.4.6 adds a real validator that rejects the tool
call before any SMTP / Graph / EWS attempt if body_text or body_html
contains tool-call wrapper syntax. The check is wired into all 5 send
paths (smtp_send_message, smtp_reply_message, smtp_forward_message,
graph_send_message, ews_send_message).<body_text>, </body_text>, <body_html>, </body_html>,
<function_calls>, </function_calls>, <invoke name=, </invoke>,
and <parameter name="body_*">. Generic technical content that happens
to mention <parameter> for an XML schema or <invoke> in a code
example still passes.serverInfo now reports name="mail-mcp" + the crate version (the
framework previously returned its own rmcp 0.16.0, which never changes
between releases). Useful for verifying the active version with /mcp, and
so any client-side cache keyed by (server, version) invalidates on each bump.Clients that resume a session with claude --continue (or /resume) do
NOT refresh the MCP system_prompt — they keep the one from that
session's first handshake. If your session predates v0.4.5, the rules won't
reach your context even if the on-disk binary is updated. To receive them,
start a NEW session in the project (not --continue).
Preview hygiene rule in MCP instructions: when the LLM shows the
user the email preview before sending, it should render ONE clean
version of the body (markdown-style bullets, bold, links as text + URL)
and state that the message will go multipart — but it must NOT dump
the raw HTML source (<p>, <strong>, <a href>...) into the
preview. Two reasons:
Complements the PREVIEW DOES NOT EQUAL TOOL CALL rule introduced in v0.4.3.
instructions block now explicitly tells the calling LLM that
body_text and body_html are TWO SEPARATE JSON fields and must
NEVER be concatenated. Previous wording ("send BOTH body_text AND
body_html") was ambiguous and some LLMs interpreted it as "concatenate
both with <body_text>...</body_html> pseudo-tags inside a single
body_text string". When that happens, the recipient sees garbled
duplicated content, AND any later Claude session that opens the saved
copy via this MCP gets a Usage Policy block (the leaked
<invoke>...</invoke> looks like a prompt-injection attempt to safety
filters). The new instruction shows a CORRECT vs WRONG example and
bans pseudo-tags / tool-call wrapper syntax inside email fields.publish-npm job in the CI release
workflow has been disabled. It was inherited from the upstream fork and
tried to publish to @bradsjm/mail-imap-mcp-rs, a scope this org does
not own — every release was 404-ing on that step. See "Releasing" below
for the full explanation and how to re-enable npm publishing if needed..github/workflows/release.yml
now fires on push: tags: ['v*'], so tagging vX.Y.Z and pushing is
all it takes to cut a release. workflow_dispatch is retained as a
manual escape hatch.init-npm-placeholder.yml workflow
(also referenced the fork's npm scope).save_to_sent_folder now archives the exact RFC822 bytes that were
sent (via lettre.formatted()), instead of a hand-rolled text-only stub.
The Sent-folder copy keeps the HTML body, the multipart/alternative
structure, and the RFC 2047-encoded subject — no more ??? where accents
used to be, and HTML is no longer silently dropped.Enviado[s], Elementos enviados, Enviadas, Itens enviados, Envoyés, Éléments envoyés,
Gesendet, Posta inviata, Verzonden, Wysłane, plus nested variants.
Previously only English names were recognized, so Zoho/localized IMAP
accounts fell through to a non-existent "Sent" folder.smtp_forward_message accepts body_html (was hardcoded to
plain-text only).bcc, in_reply_to, references (via
<t:InternetMessageHeaders>), plus full recipient + subject-length
validation — now at parity with the SMTP and Graph send paths.WARN when the
message-lookup HTTP call fails (rate limit, 5xx, permissions) so operators
see threading degraded due to a real error; DEBUG when the original
message is legitimately not found.quick-xml. Fixes a latent namespace-collision bug (<soap:Body> vs
<t:Body>), correctly decodes XML entities and CDATA, and handles
attribute values containing = (common in base64-like EWS item IDs).cargo build --release.| mail-mcp | Typical email MCP | |
|---|---|---|
| IMAP read/write | 18 tools | 3-5 tools |
| SMTP send/reply/forward | Yes | No or broken |
| Microsoft Graph API | Yes | No |
| EWS (Exchange Web Services) | Yes | No |
| OAuth2 (XOAUTH2) | Native | No |
| Multi-account | Yes | Single account |
| Microsoft 365 + Hotmail | Both work | Usually neither |
| Language | Rust (fast, safe) | TypeScript/Python |
| Tests | 64 unit + integration | Mocks only |
| Warnings in release build | 0 | Varies |
| Provider | IMAP | SMTP | Graph API | EWS | OAuth2 | Multi-account |
|---|---|---|---|---|---|---|
| Microsoft 365 (enterprise) | Yes | Admin-dependent | Yes | Yes | Yes | Yes |
| Hotmail / Outlook.com | Yes | Blocked by MS | Yes | Yes | Yes | Yes |
| Gmail | Yes | Yes | — | — | Yes | Yes |
| Apple iCloud | Yes | Yes | — | — | — | Yes |
| Zoho | Yes | Yes | — | — | — | Yes |
| Fastmail | Yes | Yes | — | — | — | Yes |
| Any IMAP/SMTP server | Yes | Yes | — | — | — | Yes |
EWS is the simplest way to add Microsoft accounts — single OAuth2 token for both reading and sending. Works even on tenants that block Graph API and IMAP.
Copy and paste this prompt into Claude Code and it will install, compile, and configure everything for you:
Install and configure the mail-mcp MCP server from https://github.com/tecnologicachile/mail-mcp
1. Clone the repo, build with cargo build --release
2. Add the MCP server to .claude.json with the binary path
3. For Microsoft accounts: use EWS (simplest) — run device code flow with
client_id d3590ed6-52b3-4102-aeff-aad2292ab01c and scope
https://outlook.office.com/EWS.AccessAsUser.All offline_access
Then configure MAIL_EWS_<ID>_USER and MAIL_EWS_<ID>_REFRESH_TOKEN
4. For Gmail: configure MAIL_IMAP + MAIL_SMTP with App Password from
https://myaccount.google.com/apppasswords
5. For Zoho: configure MAIL_IMAP + MAIL_SMTP with standard password
6. Enable write/send: MAIL_IMAP_WRITE_ENABLED=true, MAIL_SMTP_WRITE_ENABLED=true
My email accounts to configure:
- <your-email@example.com>
Replace the last line with your email(s). Claude Code will guide you through each step including the OAuth2 device code flow for Microsoft accounts.
Install a prebuilt binary:
# macOS and Linux (Homebrew)
brew install tecnologicachile/tap/mail-mcp
# macOS and Linux (shell installer)
curl --proto '=https' --tlsv1.2 -LsSf https://github.com/tecnologicachile/mail-mcp/releases/latest/download/mail-mcp-installer.sh | sh
The shell and PowerShell installers also install mail-mcp-update, which
updates an existing install to the latest release. With Homebrew, use
brew upgrade mail-mcp.
# Windows
powershell -ExecutionPolicy Bypass -c "irm https://github.com/tecnologicachile/mail-mcp/releases/latest/download/mail-mcp-installer.ps1 | iex"
Or build from source:
git clone https://github.com/tecnologicachile/mail-mcp.git
cd mail-mcp
cargo build --release
Create the default TOML file and add an account in a terminal. For a source
build, replace mail-mcp with ./target/release/mail-mcp:
mail-mcp config init
mail-mcp accounts add
mail-mcp accounts list
mail-mcp config validate
mail-mcp accounts test default
Choose default as the account ID above, or substitute the chosen ID in the
test command. Passwords and tokens use hidden prompts. OAuth accounts require
credentials obtained beforehand; the CLI does not perform initial login or
token acquisition. config init refuses to overwrite a file, and connection
tests do not send or change mail.
Add this entry to the MCP client configuration (Claude Code, Cursor, etc.):
{
"mcpServers": {
"mail": {
"command": "mail-mcp"
}
}
}
Use an absolute binary path if necessary. The server loads
~/.mail-mcp/config.toml; no credentials are needed in the client JSON.
Writes, sends, and drafts remain disabled until enabled in the configuration.
--config PATH takes precedence over MAIL_CONFIG_FILE, then the default path.
Process MAIL_* settings override file fields. Implicit .env loading applies
only when no TOML path is explicitly selected and no default TOML file exists.
See guided setup and account management
and the TOML reference for
edit/remove commands, all fields, and an MCP-client MAIL_CONFIG_FILE example.
Environment-only setup remains supported. Instead of creating a TOML file,
place account settings in the MCP client's env object. With a prebuilt
binary, use "command": "mail-mcp":
{
"mcpServers": {
"mail": {
"command": "./target/release/mail-mcp",
"env": {
"MAIL_IMAP_DEFAULT_HOST": "imap.gmail.com",
"MAIL_IMAP_DEFAULT_USER": "you@gmail.com",
"MAIL_IMAP_DEFAULT_PASS": "your-app-password",
"MAIL_SMTP_DEFAULT_HOST": "smtp.gmail.com",
"MAIL_SMTP_DEFAULT_PORT": "587",
"MAIL_SMTP_DEFAULT_USER": "you@gmail.com",
"MAIL_SMTP_DEFAULT_PASS": "your-app-password",
"MAIL_SMTP_DEFAULT_SECURE": "starttls",
"MAIL_IMAP_WRITE_ENABLED": "true",
"MAIL_SMTP_WRITE_ENABLED": "true"
}
}
}
}
This environment example explicitly enables read, write, and send operations.
A default ~/.mail-mcp/config.toml applies to every client that does not
select a file, including this one. Add "MAIL_CONFIG_FILE": "none" to the
env object to keep the client environment-only.
Microsoft blocks SMTP on personal accounts. Use Graph API instead:
{
"env": {
"MAIL_IMAP_DEFAULT_HOST": "outlook.office365.com",
"MAIL_IMAP_DEFAULT_USER": "you@hotmail.com",
"MAIL_IMAP_DEFAULT_PASS": "your-app-password",
"MAIL_OAUTH2_DEFAULT_PROVIDER": "microsoft",
"MAIL_OAUTH2_DEFAULT_CLIENT_ID": "9e5f94bc-e8a4-4e73-b8be-63364c29d753",
"MAIL_OAUTH2_DEFAULT_CLIENT_SECRET": "none",
"MAIL_OAUTH2_DEFAULT_REFRESH_TOKEN": "<your-token>"
}
}
Get your token in 1 minute with device code flow. See Account Setup Guide.
| Tool | What it does |
|---|---|
list_all_accounts | List all accounts with capabilities (IMAP, SMTP, Graph, EWS) |
imap_list_accounts | List IMAP accounts |
imap_verify_account | Test connectivity and auth |
imap_list_mailboxes | List folders |
imap_mailbox_status | Message counts |
imap_search_messages | Search with cursor pagination; thread_message_id finds a message and its replies |
imap_search_all_mailboxes | Same criteria in every mailbox at once (e.g. a whole conversation spread over INBOX, Sent and project folders), newest first, labelled with the mailbox |
imap_get_message | Parsed message (text, HTML, attachments) |
imap_get_message_raw | RFC822 source |
imap_get_attachment | Download one attachment to disk (bypasses the raw size cap) |
| Tool | What it does |
|---|---|
imap_update_message_flags | Add/remove flags |
imap_copy_message | Copy (cross-account supported) |
imap_move_message | Move to folder |
imap_delete_message | Delete with confirmation |
imap_create_mailbox | Create folder |
imap_delete_mailbox | Delete folder |
imap_rename_mailbox | Rename folder |
imap_append_message | Append raw message |
imap_bulk_move | Move up to 500 at once |
imap_bulk_delete | Delete up to 500 at once |
imap_bulk_update_flags | Flag up to 500 at once |
| Tool | What it does |
|---|---|
smtp_send_message | Send email (text/HTML, CC/BCC) |
smtp_reply_message | Reply with threading headers |
smtp_forward_message | Forward with original inline |
smtp_verify_account | Test SMTP connectivity |
graph_send_message | Send via Microsoft Graph API (with reply threading) |
| Tool | What it does |
|---|---|
ews_search_messages | Search emails via EWS (inbox, sent, drafts, etc.) |
ews_get_message | Get full email content via EWS |
ews_send_message | Send email via EWS |
The agent prepares the email, a person reviews it in their mail client (or
asks the agent to send it). One set of tools for every account: drafts go to
the IMAP Drafts folder, or through EWS or Microsoft Graph when the account is
configured for them (list_all_accounts shows drafts_with).
| Tool | What it does |
|---|---|
draft_create | Save a new draft (CC/BCC, HTML, attachments, threading) |
draft_update | Replace a draft's content; returns a new draft_id |
draft_send | Send a draft and remove it from Drafts |
draft_delete | Delete a draft (only drafts; needs confirm: true) |
draft_list | List drafts, newest first |
Enable with MAIL_DRAFTS_ENABLED=true. It is independent of
MAIL_IMAP_WRITE_ENABLED: with only drafts enabled, the agent can write
drafts but cannot move, flag or delete other mail, and every draft tool
refuses ids that are not drafts. draft_send additionally needs
MAIL_SMTP_WRITE_ENABLED=true. Graph accounts need the Mail.ReadWrite
scope.
Send files with any send tool. Two modes:
// Large files — MCP reads from disk (recommended)
"attachments": [{"file_path": "/path/to/report.pdf"}]
// Small files — inline base64
"attachments": [{"filename": "note.txt", "content_type": "text/plain", "content_base64": "SGVsbG8="}]
Filename and MIME type are auto-detected from the file path. Reply with include_original_attachments: true to forward original attachments.
Downloading an attachment from a received message: use imap_get_attachment
with the message_id and a part_id (from imap_get_message) or filename.
It writes the decoded file to disk and returns the path — no size cap, and the
binary stays out of the response. Set the default download directory with
MAIL_ATTACHMENT_DOWNLOAD_DIR (falls back to the system temp dir), or pass
output_dir per call.
To limit which local files send tools may attach via file_path, set
MAIL_ATTACHMENT_UPLOAD_DIR; paths outside it (including via .. or
symlinks) are rejected. See docs/security.md.
| Tool | What it does |
|---|---|
imap_search_and_move | Search + move matches |
imap_search_and_delete | Search + delete matches |
| Tool | What it does |
|---|---|
get_setup_guide | Provider-specific setup instructions (Microsoft OAuth2, Gmail/iCloud App Passwords, Zoho, etc.) |
Configure as many accounts as you need:
# Gmail
MAIL_IMAP_GMAIL_HOST=imap.gmail.com
MAIL_IMAP_GMAIL_USER=me@gmail.com
MAIL_IMAP_GMAIL_PASS=app-password
# Apple iCloud (App-Specific Password from appleid.apple.com)
MAIL_IMAP_ICLOUD_HOST=imap.mail.me.com
MAIL_IMAP_ICLOUD_USER=you@icloud.com
MAIL_IMAP_ICLOUD_PASS=app-specific-password
MAIL_SMTP_ICLOUD_HOST=smtp.mail.me.com
MAIL_SMTP_ICLOUD_USER=you@icloud.com
MAIL_SMTP_ICLOUD_PASS=app-specific-password
MAIL_SMTP_ICLOUD_SECURE=starttls
# Microsoft 365
MAIL_IMAP_WORK_HOST=outlook.office365.com
MAIL_IMAP_WORK_USER=me@company.com
MAIL_OAUTH2_WORK_PROVIDER=microsoft
MAIL_OAUTH2_WORK_CLIENT_ID=your-client-id
MAIL_OAUTH2_WORK_CLIENT_SECRET=none
MAIL_OAUTH2_WORK_REFRESH_TOKEN=your-token
# Zoho
MAIL_IMAP_DEFAULT_HOST=imap.zoho.com
MAIL_IMAP_DEFAULT_USER=info@mydomain.com
MAIL_IMAP_DEFAULT_PASS=password
MAIL_SMTP_DEFAULT_HOST=smtp.zoho.com
MAIL_SMTP_DEFAULT_USER=info@mydomain.com
MAIL_SMTP_DEFAULT_PASS=password
MAIL_SMTP_DEFAULT_SECURE=starttls
Use account_id in tool calls: "account_id": "gmail", "account_id": "icloud", "account_id": "work", "account_id": "default".
MAIL_IMAP_WRITE_ENABLED=trueMAIL_SMTP_WRITE_ENABLED=trueMAIL_DRAFTS_ENABLED=true allows writing drafts without any other write accessconfirm: trueMAIL_MCP_TRANSPORT=http binds to loopback unless told otherwise, and belongs behind an authenticating gatewayFor TOML fields, account examples, path selection, and environment overrides, see the TOML configuration reference.
| Variable | Required | Default | Description |
|---|---|---|---|
MAIL_IMAP_<ID>_HOST | Yes | — | IMAP server |
MAIL_IMAP_<ID>_PORT | No | 993 | IMAP port |
MAIL_IMAP_<ID>_USER | Yes | — | Username |
MAIL_IMAP_<ID>_PASS | Yes* | — | Password (*optional with OAuth2) |
MAIL_IMAP_<ID>_SECURE | No | true | Use TLS |
| Variable | Required | Default | Description |
|---|---|---|---|
MAIL_SMTP_<ID>_HOST | Yes | — | SMTP server |
MAIL_SMTP_<ID>_PORT | No | 587 | SMTP port |
MAIL_SMTP_<ID>_USER | Yes | — | Username |
MAIL_SMTP_<ID>_PASS | No | — | Password (optional with OAuth2) |
MAIL_SMTP_<ID>_SECURE | No | starttls | starttls, tls, or plain |
MAIL_SMTP_<ID>_FROM_EMAIL | No | = _USER | Sender address when it differs from the SMTP auth username (e.g. shared/group mailboxes) |
| Variable | Required | Default | Description |
|---|---|---|---|
MAIL_OAUTH2_<ID>_PROVIDER | Yes | — | google or microsoft |
MAIL_OAUTH2_<ID>_CLIENT_ID | Yes* | — | OAuth2 client ID |
MAIL_OAUTH2_<ID>_CLIENT_SECRET | No | — | Client secret; omit (or none) for public clients |
MAIL_OAUTH2_<ID>_REFRESH_TOKEN | Yes* | — | Refresh token |
MAIL_OAUTH2_<ID>_ACCESS_TOKEN | No | — | Host-managed access token, used as is and never refreshed. Environment or .env only, not a TOML field |
* Not needed when MAIL_OAUTH2_<ID>_ACCESS_TOKEN is set.
| Variable | Required | Default | Description |
|---|---|---|---|
MAIL_GRAPH_<ID>_PROVIDER | Yes | — | microsoft |
MAIL_GRAPH_<ID>_CLIENT_ID | Yes | — | OAuth2 client ID |
MAIL_GRAPH_<ID>_CLIENT_SECRET | No | — | Client secret; omit (or none) for public clients |
MAIL_GRAPH_<ID>_REFRESH_TOKEN | Yes | — | Refresh token (Mail.Send scope) |
| Variable | Required | Default | Description |
|---|---|---|---|
MAIL_EWS_<ID>_USER | Yes | — | Email address |
MAIL_EWS_<ID>_REFRESH_TOKEN | Yes | — | OAuth2 refresh token (EWS scope) |
MAIL_EWS_<ID>_CLIENT_ID | No | d3590ed6... (Microsoft Office) | OAuth2 client ID |
MAIL_EWS_<ID>_CLIENT_SECRET | No | none | Client secret |
Tip: EWS only needs 2 variables (USER + REFRESH_TOKEN). Client ID defaults to Microsoft Office which has all permissions pre-approved.
| Variable | Default | Description |
|---|---|---|
MAIL_IMAP_WRITE_ENABLED | false | Enable IMAP write operations |
MAIL_SMTP_WRITE_ENABLED | false | Enable SMTP/Graph send operations |
MAIL_DRAFTS_ENABLED | false | Enable the draft tools (draft_send also needs MAIL_SMTP_WRITE_ENABLED) |
MAIL_SMTP_SAVE_SENT | unset | Global Sent-copy override; per-account choice wins, otherwise Gmail/Zoho skip the IMAP copy and other hosts save it |
MAIL_SMTP_CONNECT_TIMEOUT_MS | 30000 | SMTP TCP/TLS/auth timeout (connect phase) |
MAIL_SMTP_SEND_TIMEOUT_MS | 300000 | SMTP DATA transmission timeout (5 min — accommodates large attachments) |
MAIL_SMTP_TIMEOUT_MS | (deprecated) | Legacy send timeout; process value overrides TOML unless MAIL_SMTP_SEND_TIMEOUT_MS is also set in the environment. Prefer the split vars above. |
MAIL_IMAP_CONNECT_TIMEOUT_MS | 30000 | TCP connection timeout |
MAIL_IMAP_GREETING_TIMEOUT_MS | 15000 | TLS/greeting timeout |
MAIL_IMAP_SOCKET_TIMEOUT_MS | 300000 | Socket I/O timeout |
MAIL_IMAP_MAX_MAILBOXES | 200 | Max mailboxes imap_list_mailboxes returns (1–10000); the response reports total and truncated |
MAIL_IMAP_SEARCH_CONCURRENCY | 4 | Parallel IMAP connections for imap_search_all_mailboxes (1–8) |
MAIL_OAUTH2_TOKEN_STORE | (unset) | File where rotated OAuth2 refresh tokens are saved so they survive a restart (see OAuth2 token store) |
MAIL_MCP_TRANSPORT | stdio | stdio, or http to serve MCP streamable HTTP (see Remote HTTP transport) |
MAIL_MCP_HTTP_HOST | 127.0.0.1 | HTTP bind address (IP literal) |
MAIL_MCP_HTTP_PORT | 8000 | HTTP bind port |
MAIL_MCP_HTTP_PATH | /mcp | HTTP endpoint path |
MAIL_DOTENV | true | Look for a legacy .env in the working directory or its parents when no TOML file applies. false turns that off: nothing is read or exported from any .env. Process environment only |
MAIL_UPDATE_CHECK | true | At startup, ask GitHub for the latest release (2 s limit) and add a notice to the server instructions when a newer one exists. false skips the request, for hosts that pin the version. Environment or .env only |
createReply flow for proper conversation threadingquick-xml — correct entity/CDATA/namespace handling (v0.4.1)| Guide | Description |
|---|---|
| Account Setup | Guided CLI setup, account management, provider credentials, and environment-only setup |
| Tool Contract | Complete tool definitions and schemas |
| Message ID Format | Stable message identifier format |
| Cursor Pagination | Pagination behavior and expiration |
| Security | Security features and best practices |
| Advanced Configuration | TOML field reference, configuration precedence, timeouts, and performance tuning |
cargo test # 64 unit + integration tests
cargo fmt -- --check # formatting
cargo clippy --all-targets -- -D warnings # linting
See AGENTS.md for contributor guidelines.
Releases are automated via cargo-dist. To ship a new version:
version = "X.Y.Z" in Cargo.toml (the release workflow enforces
that this matches the pushed tag).main.git tag vX.Y.Z
git push origin main --tags
push: tags: ['v*'] trigger in .github/workflows/release.yml
compiles binaries for Linux / macOS (Intel + Apple Silicon) / Windows,
generates installer scripts (.sh, .ps1), creates the GitHub Release,
and attaches all artifacts with SHA256 checksums.workflow_dispatch trigger is preserved as an escape hatch).npm publishing is intentionally disabled. The upstream fork was
configured to publish as @bradsjm/mail-imap-mcp-rs, a scope this
organization does not own, which caused every release to 404 on npm publish. The npm tarball is still generated and attached to each GitHub
Release so users can install via npm install ./mail-mcp-npm-package.tar.gz
manually. To enable npm registry publishing for this fork: create an npm
org (e.g. @tecnologicachile), configure Trusted Publishing on
npmjs.com pointing at this repo, set publish-jobs = ["npm"] in
dist-workspace.toml, and run dist generate --allow-dirty to restore
the publish-npm job in release.yml.
Contributions welcome! Check out the issues for good first issues.
If mail-mcp is useful to you, a ⭐ on the repo helps others discover it.
MIT License — see LICENSE for details.
Loading reviews...
GitHub checked 40h ago - refresh overdue. Recently viewed repositories target hourly refresh.
Find a documented setup for your client. No sign-in, installation, or tool execution.
If this MCP is also published on mcpchannel.ai, you can subscribe from Browse and use the gateway config there instead.