An MCP server that gives AI agents controlled access to IMAP and SMTP mailboxes — read, search, organize, and send — without ever handing them your credentials.
Written in Go. Single static binary, no runtime dependencies, ~20 MB resident.
Why credentials stay server-side
The agent never sees a hostname, username, or password. Tools take an opaque ; the server resolves it against a local config file and makes the connection itself. Run it remotely and the model has no way to reconstruct how to reach your mailbox, even if it wanted to.
MCP server bridging IMAP/SMTP email accounts to Poke — search, read, send, and watch emails via AI agents
星标
12
工具
—
可用率
—
account_id
The same idea extends to message handles. A message_id is an opaque token encoding the account, folder, UIDVALIDITY, and UID together — so an agent cannot pair a handle from one mailbox with a different account, and a folder that gets renumbered produces a clear "this handle is stale" error instead of quietly acting on the wrong message.
Most providers need an app-specific password rather than your account password — iCloud, Gmail, Fastmail, and Zoho all work this way.
SMTP inherits the IMAP host and credentials when omitted, and connection security is inferred from the port (993 → TLS, 143 → STARTTLS, 465 → TLS, 587 → STARTTLS) unless you set security explicitly.
The HTTP transport refuses to start without MCP_API_KEY. There is no unauthenticated mode — this process can read and send your mail.
3. Verify.
npx @modelcontextprotocol/inspector
Connect to http://localhost:3000/mcp over Streamable HTTP with an Authorization: Bearer <MCP_API_KEY> header, then call verify_account to confirm both IMAP and SMTP authenticate.
Local use
For a client on the same machine, stdio skips the network entirely and needs no token:
Attachment bytes never enter the response.read_email returns attachment metadata with a part_id; get_attachment writes the file to disk and returns file_path (on the server) plus, when public_url is set, a 15-minute signed download_url. A remote agent curls that URL onto its own machine. A 7 MB PDF base64-encoded into a tool result would blow the context window without accomplishing anything.
Bodies are truncated and HTML is opt-in. Message HTML is attacker-controlled and enormous. It is sanitized through bluemonday before it is ever returned, and omitted entirely unless include_html is set. Messages with no plain-text part get one derived from the HTML, with paragraph breaks preserved.
One pooled IMAP connection per account. A TLS handshake plus LOGIN on every tool call is the single biggest source of latency in servers of this kind. Connections are kept authenticated, health-checked with NOOP after idling, and reconnected transparently. Operations on one account are serialized, since IMAP's selected-mailbox state makes ordering matter; different accounts run concurrently.
Every network operation is bounded. Separate timeouts for IMAP connect, IMAP command, SMTP connect, and SMTP send — the last one generous, because DATA transmission for a large attachment on a slow uplink legitimately takes minutes. A command that exceeds its budget closes the socket, which is the only thing that reliably unblocks a stuck IMAP read.
Sent copies are the exact bytes that were delivered. Rather than rebuilding an approximation for the Sent folder, the serialized message is captured before transmission and APPENDed verbatim. Whether to append at all is provider-aware: Gmail and Zoho file their own copy on submission, so a second one is redundant or a visible duplicate; iCloud, Office 365, and generic relays file nothing, so skipping it loses the copy.
Send validation happens before a socket opens. Recipients, subject length, header injection via embedded newlines, and body presence are all checked locally. A malformed call fails instantly with a specific message instead of after a TLS handshake.
Tool-call syntax in a body is rejected outright. LLMs periodically concatenate body_text and body_html into one argument and leak the separator markup into the recipient's inbox. Prompt instructions do not reliably prevent this, so the server refuses any send whose fields contain </body_text>, <parameter name="body_html">, and similar markers. Legitimate technical content that merely mentions <parameter> still passes.
Folder roles come from the server, not a name list. SPECIAL-USE attributes are used where available, with a localized name table as fallback — so a Polish "Wysłane" or a Gmail "[Gmail]/Sent Mail" is recognized as Sent rather than triggering the creation of a duplicate folder.
Destructive operations are gated twice.allow_delete is false by default, and even when enabled delete_email requires confirm: true per call and moves to Trash rather than expunging. delete_folder additionally refuses INBOX and any special-use folder.
Configuration reference
Environment
Variable
Default
Purpose
MCP_API_KEY
—
Bearer token. Required for HTTP; unused for stdio.
Configs written for poke-mail v1 still load: the flat imap_host / smtp_username style keys are folded into the nested form automatically.
Security
Authentication is mandatory on HTTP. No token, no start.
Credentials never leave the server. Tools receive ids, not connection details.
Everything outside /mcp returns an empty 404, revealing nothing to scanners.
TLS is mandatory for STARTTLS accounts. No opportunistic fallback to plaintext, which would send your password in the clear.
Rate limited per client, with separate GET and POST budgets so polling cannot starve real work. X-Forwarded-For is ignored unless you declare a trusted proxy, since otherwise any caller could spoof it.
Attachment filenames are sanitized before touching the filesystem — path separators, traversal segments, and control characters are stripped.
HTML is sanitized with bluemonday before it is returned.
DNS rebinding protection is on by default via the MCP SDK.
Put it behind TLS in any real deployment — a reverse proxy or a tunnel. The bearer token is the only thing standing between the internet and your mail.
Development
make check # fmt + vet + test
make test
make race
make cover
make build
make docker