
snagmail
io.github.Sahilhirapara/snagmail
Local SMTP catcher that hands OTP codes and magic links to AI agents and tests over MCP.
Documentation
snagmail
Local fake SMTP server + MCP server. Your app's outgoing test mail never leaves localhost;
OTP codes and verification links are extracted for you and handed to AI agents (MCP) or test suites (REST).
Receive-only: it never sends mail. In-memory, no Docker, no database.
Quick start
npx snagmail
Needs Node.js 20.19 or newer.
- SMTP catcher:
127.0.0.1:1025(and[::1]:1025) - Web UI, REST API, MCP (
/mcp):http://127.0.0.1:8025
Point your app at it:
SMTP_HOST=127.0.0.1
SMTP_PORT=1025
SMTP_SECURE=false
SMTP_HOST=localhost works too: by default snagmail listens on both 127.0.0.1 and ::1, so it doesn't matter which one your OS resolves localhost to.
MCP setup
Stdio (the client launches snagmail itself; it also starts the SMTP catcher and UI):
claude mcp add --transport stdio snagmail -- npx -y snagmail --mcp-stdio
Claude Code .mcp.json, Cursor .cursor/mcp.json, Claude Desktop (all use mcpServers):
{ "mcpServers": { "snagmail": { "command": "npx", "args": ["-y", "snagmail", "--mcp-stdio"] } } }
VS Code .vscode/mcp.json (this file uses servers, not mcpServers):
{ "servers": { "snagmail": { "type": "stdio", "command": "npx", "args": ["-y", "snagmail", "--mcp-stdio"] } } }
HTTP (run npx snagmail yourself, then connect; use this when several windows/agents share one inbox):
claude mcp add --transport http snagmail http://127.0.0.1:8025/mcp
Claude Code .mcp.json:
{ "mcpServers": { "snagmail": { "type": "http", "url": "http://127.0.0.1:8025/mcp" } } }
Cursor .cursor/mcp.json:
{ "mcpServers": { "snagmail": { "url": "http://127.0.0.1:8025/mcp" } } }
VS Code .vscode/mcp.json:
{ "servers": { "snagmail": { "type": "http", "url": "http://127.0.0.1:8025/mcp" } } }
Only one snagmail can own the SMTP port. A second instance exits with an error; connect to the first one over HTTP instead.
MCP tools
| Tool | Params |
|---|---|
wait_for_email | to (* wildcard), subject_contains, timeout_ms (default 30000, max 300000), since_timestamp |
list_emails | to, limit (default 10) |
get_email | id, format: clean_text | html | raw |
clear_inbox | to |
wait_for_email returns the newest matching email already in the inbox, or waits for a new one.
For repeat tests on the same address, call clear_inbox first, pass since_timestamp, or use a unique recipient.
to matches the SMTP envelope recipient (so BCC works), case-insensitive.
Result: id, from, to, envelope_to, header_to, cc, subject, extracted_otp, action_links[{type,label,url}], clean_text, received_at.
Link types: verify, reset_password, magic_link, unsubscribe, other.
CLI flags
--host <addr> Address to listen on (default: localhost = 127.0.0.1 and ::1)
--smtp-port <port> SMTP port (default 1025)
--http-port <port> Web UI, REST, /mcp port (default 8025)
--mcp-stdio Serve MCP over stdio (all logs go to stderr)
--no-ui Skip the HTTP server (only with --mcp-stdio)
--max-emails <n> Emails kept in memory (default 200)
If the HTTP port is busy in --mcp-stdio mode, snagmail warns on stderr and keeps running without the UI.
Docker / WSL: --host
Apps in a container or in WSL can't reach the host's 127.0.0.1. Listen on every interface instead:
npx snagmail --host 0.0.0.0
then point the app at the host, e.g. SMTP_HOST=host.docker.internal (Docker Desktop) or the host's IP. snagmail prints a warning
whenever --host isn't a loopback address, see Security. To bind one specific interface use its address, e.g. --host 192.168.1.5.
REST API
| Endpoint | |
|---|---|
GET /api/v1/emails?to=&search=&limit= | list (no bodies) |
GET /api/v1/emails/wait?to=&subject_contains=&since_timestamp=&timeout_ms= | long poll; 408 on timeout |
GET /api/v1/emails/:id | full email incl. html, raw |
DELETE /api/v1/emails?to= | clear all or filtered |
GET /api/v1/info | { smtp_port, http_port, host, version } |
WS /ws | live feed (email, clear) |
Example (CI): curl "http://127.0.0.1:8025/api/v1/emails/wait?to=qa@test.local&timeout_ms=10000"
Security
By default it listens on loopback only (127.0.0.1 and ::1), validates the Host and Origin headers (DNS-rebinding and cross-site WebSocket protection), and the UI previews HTML in a script-less sandboxed iframe with remote loads blocked.
--host with a non-loopback address (e.g. 0.0.0.0) removes that isolation. SMTP, the REST API and /mcp have no authentication, so anyone who can reach the address can read every captured email, clear the inbox or inject mail. In that mode the Host allowlist is off (Docker reaches you as host.docker.internal or an IP) and the WebSocket only accepts same-origin pages. Use it on trusted networks only.
Dev
npm run dev · npm test · npm run build
snagmailnpm install snagmail