Mail MCP Server

1

Add it to Claude Code

Run this in a terminal.

Run in terminal
claude mcp add -e "SMTP_HOST=${SMTP_HOST}" -e "SMTP_PASSWORD=${SMTP_PASSWORD}" -e "EMAIL_FROM=${EMAIL_FROM}" mail-mcp-98c6 -- docker run --rm -p 8000:8000 --env-file .env mail-mcp-server:latest
Required:SMTP_HOSTSMTP_PASSWORDEMAIL_FROM+ 2 optional
README.md

An MCP server that provides email sending capabilities via SMTP

Mail MCP Server

基于 FastMCP 的邮件发送能力,以 MCP Streamable HTTP 传输启动,供支持该协议的客户端通过 HTTP 连接(无需 stdio 子进程)。

Features

  • 传输streamable-http(FastMCP 内与 http / sse 并列的 transport)
  • MCP 工具send_emailsend_template_email
  • 监听MCP_HOST / MCP_PORT(默认 0.0.0.0:8000
  • Docker 镜像非 root 运行,依赖层与代码层分离缓存

Prerequisites

Project Structure

mail-mcp-server
├── src
│   ├── mcp_server.py          # MCP 入口(streamable-http)
│   ├── main.py
│   ├── email_service/
│   └── tests/
├── pyproject.toml
├── uv.lock
├── Dockerfile
├── docker-compose.yml
├── .dockerignore
├── .env.example
└── README.md

启动

cd mail-mcp-server
cp .env.example .env
uv sync
uv run python src/mcp_server.py

Streamable HTTP 端点:http://<MCP_HOST>:<MCP_PORT>/mcp(例如 http://127.0.0.1:8000/mcp)。

.env 为何未生效?

.envload_env 说明:需在项目根放置 .env,修改后重启 MCP 进程

环境变量

变量 说明 默认
MCP_HOST / MCP_PORT 监听 0.0.0.0 / 8000
SMTP_* / DEFAULT_SENDER / EMAIL_FROM 发信 .env.example
SMTP_SSL / SMTP_USE_STARTTLS 465 / 587 fastmcp_client.py 与 README 163 小节

163 `Connection unexpectedly closed`

问题 处理
用户名非完整邮箱 使用 user@163.com
FROM 写成授权码 FROM 必须是邮箱;授权码只在 SMTP_PASSWORD
587 被断开 使用 SMTP_PORT=465 + SMTP_SSL=true,或依赖自动走 465

一次性演示(非 MCP)

uv run python src/main.py

Docker

镜像特点

说明
分层 pyproject.toml + uv.lock + uv sync,再 COPY src/,改代码不重建依赖层
环境 UV_LINK_MODE=copy--compile-bytecode,减少告警并略加快启动
安全 USER app(uid 1000),非 root
布局 PYTHONPATH=/app/srcCMDpython -m mcp_server

构建

# 默认 bookworm + Python 3.10
docker build -t mail-mcp-server:latest .

# 加快构建(跳过 apt upgrade)
docker build --build-arg SKIP_APT_UPGRADE=1 -t mail-mcp-server:latest .

# 指定 Python 小版本
docker build --build-arg PYTHON_VERSION=3.11 -t mail-mcp-server:py311 .

运行

docker run --rm -p 8000:8000 --env-file .env mail-mcp-server:latest

Compose

服务名 mail-mcp(原 email-sender 已更名):

docker compose up --build -d
  • 端口:宿主机 ${MCP_PORT:-8000} → 容器 8000(容器内仍监听 8000,改端口请同时设置环境变量并映射)。
  • healthcheck:对容器内 127.0.0.1:8000 做 TCP 探测(Streamable HTTP 未必有 GET /)。
  • 重启策略:unless-stopped

Development

uv sync --group dev
uv run pytest
uv lock

License

MIT

Tools (2)

send_emailSends a standard email message.
send_template_emailSends an email using a predefined template.

Environment Variables

MCP_HOSTHost address for the MCP server
MCP_PORTPort for the MCP server
SMTP_HOSTrequiredSMTP server address
SMTP_PASSWORDrequiredSMTP password or authorization code
EMAIL_FROMrequiredDefault sender email address

Configuration

claude_desktop_config.json
{ "mcpServers": { "mail-mcp": { "command": "python", "args": ["src/mcp_server.py"], "env": { "SMTP_HOST": "smtp.example.com", "SMTP_PORT": "587", "SMTP_USER": "user@example.com", "SMTP_PASSWORD": "your-password", "EMAIL_FROM": "sender@example.com" } } } }

Try it

Send an email to support@example.com with the subject 'Issue Report' and body 'I am experiencing a login error.'
Use the send_template_email tool to send a welcome email to new_user@example.com using the 'welcome_template'.
Send a notification email to my team about the project update.

Frequently Asked Questions

What are the key features of Mail MCP Server?

Supports standard email sending via SMTP. Provides template-based email functionality. Utilizes Streamable HTTP transport for flexible connectivity. Docker-ready with non-root user security. Supports both SSL and STARTTLS configurations.

What can I use Mail MCP Server for?

Automating transactional email notifications from AI workflows. Sending status reports directly from Claude to team members. Integrating email capabilities into local development environments without complex setups.

How do I install Mail MCP Server?

Install Mail MCP Server by running: uv sync && uv run python src/mcp_server.py

What MCP clients work with Mail MCP Server?

Mail MCP Server works with any MCP-compatible client including Claude Desktop, Claude Code, Cursor, and other editors with MCP support.

Turn this server into reusable context

Keep Mail MCP Server docs, env vars, and workflow notes in Conare so your agent carries them across sessions.

Need the old visual installer? Open Conare IDE.
Open Conare