imap-smtp-mcp
Exposes any IMAP mailbox and SMTP relay as MCP tools, enabling email management (read, search, send, delete) through MCP-compatible agents.
README
imap-smtp-mcp
Universal IMAP/SMTP ↔ MCP bridge. Expose any IMAP mailbox and SMTP relay as Model Context Protocol tools, so any MCP-compatible agent (Claude Code, Hermes, your own scripts) can read, search, send, and manage email.
┌──────────────────┐ httpStream + SSE ┌──────────────────┐ IMAP ┌────────────┐
│ MCP client │ ──────────────────►│ imap-smtp-mcp │ ───────►│ Mail │
│ (Claude, │ │ (this server) │ │ server │
│ Hermes, etc.) │ │ │ SMTP │ (any) │
└──────────────────┘ └──────────────────┘ ───────►└────────────┘
✨ Features
- 8 MCP tools:
server_info,list_mailboxes,list_emails,read_email,search_emails,send_email,mark_read,delete_email. - Universal: works with any IMAP/SMTP server (Gmail, Outlook, Fastmail, ProtonMail, Dovecot, Stalwart, Postfix, etc.).
- Transport: FastMCP 3.x with
httpStream(per-session, server-sent events) andstdio(for desktop integration). - Production-ready: graceful shutdown, persistent connections, structured logging, error handling.
- No secrets in code: configuration via environment variables only.
📦 Installation
Prerequisites
- Node.js ≥ 18
- An IMAP/SMTP-enabled mailbox
- For Gmail/Yahoo/Microsoft: an app password (not your account password). See provider-specific notes below.
From npm (once published)
npm install -g imap-smtp-mcp
imap-smtp-mcp
From source
git clone https://github.com/YOUR_USERNAME/imap-smtp-mcp.git
cd imap-smtp-mcp
npm install
npm run build
npm start
Development mode (with hot reload)
npm run dev
⚙️ Configuration
All configuration is via environment variables. Create a .env file or
export them in your shell / systemd unit.
Required
| Variable | Description |
|---|---|
IMAP_HOST |
IMAP server hostname (e.g. imap.gmail.com) |
IMAP_USER |
IMAP username (often your full email address) |
IMAP_PASS |
IMAP password or app password |
SMTP_HOST |
SMTP server hostname (often same as IMAP host) |
SMTP_USER |
SMTP username |
SMTP_PASS |
SMTP password or app password |
Optional
| Variable | Default | Description |
|---|---|---|
IMAP_PORT |
993 |
IMAP port (993 for SSL, 143 for STARTTLS) |
IMAP_SECURE |
true |
Use TLS (set false for STARTTLS or plaintext) |
IMAP_REJECT_UNAUTHORIZED |
false |
Reject invalid TLS certs (set true for production) |
SMTP_PORT |
465 |
SMTP port (465 for SSL, 587 for STARTTLS) |
SMTP_SECURE |
true |
Use TLS |
SMTP_REJECT_UNAUTHORIZED |
false |
Reject invalid TLS certs |
SMTP_FROM |
SMTP_USER |
"From" address (if different from SMTP_USER) |
FASTMCP_TRANSPORT |
httpStream |
httpStream or stdio |
FASTMCP_PORT |
3143 |
HTTP port (only for httpStream) |
FASTMCP_HOST |
0.0.0.0 |
Bind address (use 127.0.0.1 for local-only) |
LOG_LEVEL |
info |
fatal, error, warn, info, debug, trace |
LOG_DIR |
./logs |
Directory for log files |
Example .env
IMAP_HOST=imap.gmail.com
IMAP_USER=you@gmail.com
IMAP_PASS=abcd efgh ijkl mnop
IMAP_PORT=993
IMAP_SECURE=true
IMAP_REJECT_UNAUTHORIZED=true
SMTP_HOST=smtp.gmail.com
SMTP_USER=you@gmail.com
SMTP_PASS=abcd efgh ijkl mnop
SMTP_PORT=465
SMTP_SECURE=true
FASTMCP_TRANSPORT=httpStream
FASTMCP_PORT=3143
FASTMCP_HOST=0.0.0.0
LOG_LEVEL=info
LOG_DIR=/var/log/imap-smtp-mcp
🚀 Usage
As a daemon (recommended)
Once configured, just run:
imap-smtp-mcp
# [INFO] HTTP Stream listening on http://0.0.0.0:3143/mcp
With systemd
# /etc/systemd/system/imap-smtp-mcp.service
[Unit]
Description=IMAP/SMTP MCP Server
After=network.target
[Service]
Type=simple
User=imap-smtp
EnvironmentFile=/etc/imap-smtp-mcp.env
ExecStart=/usr/bin/node /opt/imap-smtp-mcp/dist/index.js
Restart=always
RestartSec=10
StandardOutput=append:/var/log/imap-smtp-mcp/mcp.log
StandardError=append:/var/log/imap-smtp-mcp/mcp.err.log
[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable --now imap-smtp-mcp
systemctl status imap-smtp-mcp
With Docker
FROM node:20-alpine
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci --omit=dev
COPY dist ./dist
ENV NODE_ENV=production
EXPOSE 3143
CMD ["node", "dist/index.js"]
docker run -d --name imap-smtp-mcp \
-p 3143:3143 \
--env-file ./.env \
imap-smtp-mcp:latest
As an MCP client (Claude Code, etc.)
{
"mcpServers": {
"mail": {
"url": "http://localhost:3143/mcp"
}
}
}
For a remote server, replace localhost with the host:
{
"mcpServers": {
"mail": {
"url": "http://localhost:3143/mcp"
}
}
}
As stdio (alternative)
If you prefer stdio transport (one process per session, e.g. for local desktop):
{
"mcpServers": {
"mail": {
"command": "node",
"args": ["/path/to/imap-smtp-mcp/dist/index.js"],
"env": {
"FASTMCP_TRANSPORT": "stdio",
"IMAP_HOST": "imap.gmail.com",
"IMAP_USER": "you@gmail.com",
"IMAP_PASS": "..."
}
}
}
}
🧰 Tools reference
server_info
Returns IMAP/SMTP server details and inbox counts.
{
"user": "you@example.com",
"imap": "imap.example.com:993",
"smtp": "smtp.example.com:465",
"inbox_total": 42,
"inbox_unread": 7
}
list_mailboxes
Lists all mailboxes with message counts.
[
{ "name": "INBOX", "total": 42, "unread": 7 },
{ "name": "Sent", "total": 15, "unread": 0 },
{ "name": "Drafts", "total": 0, "unread": 0 }
]
list_emails
Lists emails in a mailbox.
| Param | Type | Default | Description |
|---|---|---|---|
mailbox |
string | INBOX |
Mailbox name |
limit |
number | 20 |
Max results (1-500) |
unread_only |
boolean | false |
Only return unread emails |
[
{
"uid": 1234,
"subject": "Hello",
"from": "alice@example.com",
"to": "you@example.com",
"date": "2026-07-25T18:00:00.000Z",
"flags": ["\\Seen"],
"preview": "First 200 chars of body..."
}
]
read_email
Reads a full email by UID.
| Param | Type | Description |
|---|---|---|
uid |
number | Email UID (from list_emails) |
mailbox |
string | Mailbox name (default INBOX) |
Returns the email with full body. body is parsed as text/plain from the MIME source.
search_emails
Searches emails by keyword (matches body text).
| Param | Type | Default | Description |
|---|---|---|---|
query |
string | (required) | Keyword |
mailbox |
string | INBOX |
Mailbox |
limit |
number | 20 |
Max results |
send_email
Sends an email via SMTP.
| Param | Type | Description |
|---|---|---|
to |
string | Recipient address |
subject |
string | Subject line |
body |
string | Plain-text body |
Returns { status: "sent", to, subject, messageId }.
mark_read
Marks an email as read or unread.
| Param | Type | Default | Description |
|---|---|---|---|
uid |
number | (required) | Email UID |
mailbox |
string | INBOX |
Mailbox |
read |
boolean | true |
true=read, false=unread |
delete_email
Marks an email as deleted and expunges it. Permanent.
| Param | Type | Default | Description |
|---|---|---|---|
uid |
number | (required) | Email UID |
mailbox |
string | INBOX |
Mailbox |
📧 Provider notes
Gmail
- Enable 2FA on your Google account
- Create an app password
- Use the app password as
IMAP_PASS/SMTP_PASS
IMAP_HOST=imap.gmail.com
IMAP_PORT=993
IMAP_SECURE=true
SMTP_HOST=smtp.gmail.com
SMTP_PORT=465
SMTP_SECURE=true
Outlook / Microsoft 365
- Enable 2FA on your Microsoft account
- Create an app password via Microsoft account security
IMAP_USERshould be your full email address
IMAP_HOST=outlook.office365.com
IMAP_PORT=993
IMAP_SECURE=true
SMTP_HOST=smtp.office365.com
SMTP_PORT=587
SMTP_SECURE=false # STARTTLS, not implicit TLS
Fastmail
IMAP_HOST=imap.fastmail.com
IMAP_PORT=993
IMAP_SECURE=true
SMTP_HOST=smtp.fastmail.com
SMTP_PORT=465
SMTP_SECURE=true
ProtonMail Bridge
Run ProtonMail Bridge locally, then:
IMAP_HOST=127.0.0.1
IMAP_PORT=1143
IMAP_SECURE=false
SMTP_HOST=127.0.0.1
SMTP_PORT=1025
SMTP_SECURE=false
IMAP_USER=your-bridge-username
IMAP_PASS=your-bridge-password
Self-hosted (Dovecot, Stalwart, Postfix, etc.)
For self-hosted mail servers with self-signed certificates:
IMAP_REJECT_UNAUTHORIZED=false
SMTP_REJECT_UNAUTHORIZED=false
For production with valid certificates (Let's Encrypt), set both to true.
Yahoo Mail
IMAP_HOST=imap.mail.yahoo.com
SMTP_HOST=smtp.mail.yahoo.com
Generate an app password in Yahoo Account Security.
🛠️ Development
Scripts
npm run build # Compile TypeScript to dist/
npm run dev # Watch mode with tsx
npm run lint # ESLint
npm test # Run unit tests (vitest)
npm run test:watch # Tests in watch mode
npm run format # Prettier
Project layout
src/
index.ts # Entry point
config.ts # Env loading + Zod validation
logger.ts # Pino logger setup
mail-service.ts # IMAP/SMTP operations
tools.ts # MCP tool definitions
tests/
config.test.ts # Config validation tests
mail-service.test.ts # MailService with mocks
tools.test.ts # Tool registration + dispatch
.github/
workflows/
ci.yml # Lint + test + build on Node 18/20/22
Adding a new tool
- Add a method to
MailService(insrc/mail-service.ts). - Register the tool in
registerMailTools(insrc/tools.ts). - Add a test in
tests/tools.test.ts.
🔒 Security
- No secrets in code. All credentials come from environment variables.
- Use app passwords, not account passwords, for Gmail/Outlook/Yahoo.
- For production, set
IMAP_REJECT_UNAUTHORIZED=trueandSMTP_REJECT_UNAUTHORIZED=truewith valid certificates. - Bind
FASTMCP_HOST=127.0.0.1if the MCP client runs on the same host. - For remote access, place behind a reverse proxy (nginx) with TLS.
📜 License
MIT — see LICENSE.
🤝 Contributing
Issues and pull requests welcome. Please run npm run lint && npm test before
submitting.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。