Email Send/Receive MCP Server

Email Send/Receive MCP Server

Enables sending and receiving emails through SMTP, IMAP, and POP3 protocols with support for attachments, HTML content, and email validation.

Category
访问服务器

README

Email Send/Receive MCP Server

A Model Context Protocol (MCP) server for sending and receiving emails via SMTP, POP3, and IMAP. Built with FastMCP 2.0 and optimized for deployment on Azure Container Apps.

Features

  • Email Sending (SMTP)

    • Send emails with validated recipient addresses
    • Support for CC and BCC
    • HTML and plain text email bodies
    • File attachments support
    • Configurable sender information
  • Email Receiving (IMAP/POP3)

    • Retrieve emails from IMAP servers
    • Support for POP3 protocol
    • Filter by mailbox/folder
    • Unread emails filtering
    • Attachment information extraction
  • Email Validation

    • RFC-compliant email address validation
    • Automatic email normalization
    • Batch validation for multiple recipients

Installation

Using uv (recommended)

# Install uv if you haven't already
curl -LsSf https://astral.sh/uv/install.sh | sh

# Clone the repository
git clone https://github.com/bedro96/email-send-mcp.git
cd email-send-mcp

# Install dependencies
uv pip install -e .

# For development with testing tools
uv pip install -e ".[dev]"

Using pip

pip install -e .

Configuration

  1. Copy the example environment file:
cp .env.example .env
  1. Edit .env with your email server credentials:
# SMTP Configuration (for sending emails)
SMTP_SERVER=smtp.gmail.com
SMTP_PORT=587
SMTP_USERNAME=your-email@example.com
SMTP_PASSWORD=your-app-password
SMTP_USE_TLS=true

# IMAP Configuration (for receiving emails)
IMAP_SERVER=imap.gmail.com
IMAP_PORT=993
IMAP_USERNAME=your-email@example.com
IMAP_PASSWORD=your-app-password
IMAP_USE_SSL=true

# POP3 Configuration (alternative for receiving emails)
POP3_SERVER=pop.gmail.com
POP3_PORT=995
POP3_USERNAME=your-email@example.com
POP3_PASSWORD=your-app-password
POP3_USE_SSL=true

# Email Settings
DEFAULT_FROM_EMAIL=your-email@example.com
DEFAULT_FROM_NAME=MCP Email Server
MAX_ATTACHMENT_SIZE_MB=25

Gmail Setup

For Gmail, you'll need to:

  1. Enable 2-factor authentication
  2. Generate an App Password: https://myaccount.google.com/apppasswords
  3. Use the App Password in the configuration

Usage

Running the MCP Server

python main.py

The server will start and expose the following MCP tools:

Available Tools

send_email

Send an email via SMTP.

Parameters:

  • recipient (required): Email address of the recipient
  • subject (required): Email subject/title
  • body (required): Email body content
  • attachments (optional): List of file paths to attach
  • cc (optional): List of CC recipients
  • bcc (optional): List of BCC recipients
  • is_html (optional): Whether the body is HTML (default: False)

Example:

send_email(
    recipient="user@example.com",
    subject="Hello from MCP",
    body="This is a test email",
    attachments=["/path/to/file.pdf"],
    cc=["cc@example.com"],
    is_html=False
)

receive_emails_imap

Receive emails using IMAP protocol.

Parameters:

  • mailbox (optional): Mailbox to read from (default: "INBOX")
  • limit (optional): Maximum number of emails to retrieve (default: 10)
  • unread_only (optional): Only retrieve unread emails (default: False)

Example:

receive_emails_imap(
    mailbox="INBOX",
    limit=5,
    unread_only=True
)

receive_emails_pop3

Receive emails using POP3 protocol.

Parameters:

  • limit (optional): Maximum number of emails to retrieve (default: 10)

Example:

receive_emails_pop3(limit=10)

Docker Deployment

Build the Docker image

docker build -t email-send-mcp .

Run the container

docker run -d \
  --name email-mcp \
  -e SMTP_SERVER=smtp.gmail.com \
  -e SMTP_PORT=587 \
  -e SMTP_USERNAME=your-email@gmail.com \
  -e SMTP_PASSWORD=your-app-password \
  -e IMAP_SERVER=imap.gmail.com \
  -e IMAP_PORT=993 \
  -e IMAP_USERNAME=your-email@gmail.com \
  -e IMAP_PASSWORD=your-app-password \
  email-send-mcp

Or use a .env file:

docker run -d --name email-mcp --env-file .env email-send-mcp

Azure Container Apps Deployment

  1. Create an Azure Container Registry (ACR)
  2. Push the Docker image to ACR
  3. Create a Container App with environment variables
  4. Configure scaling and networking as needed

Example Azure CLI commands:

# Build and push to ACR
az acr build --registry <your-acr-name> --image email-send-mcp:latest .

# Create Container App
az containerapp create \
  --name email-send-mcp \
  --resource-group <your-rg> \
  --environment <your-env> \
  --image <your-acr-name>.azurecr.io/email-send-mcp:latest \
  --env-vars \
    SMTP_SERVER=smtp.gmail.com \
    SMTP_PORT=587 \
    SMTP_USERNAME=secretref:smtp-username \
    SMTP_PASSWORD=secretref:smtp-password

Development

Running Tests

pytest tests/ -v

Code Formatting

black src/ tests/ main.py
isort src/ tests/ main.py

Type Checking

mypy src/

Architecture

email-send-mcp/
├── main.py                 # Entry point
├── src/
│   ├── __init__.py
│   ├── config.py          # Configuration management
│   ├── server.py          # FastMCP server setup
│   ├── services/
│   │   ├── email_sender.py    # SMTP service
│   │   └── email_receiver.py  # IMAP/POP3 service
│   └── utils/
│       └── validators.py      # Email validation
├── tests/                 # Test files
├── Dockerfile            # Container configuration
├── pyproject.toml        # Project dependencies
└── .env.example          # Example configuration

Technology Stack

  • FastMCP 2.0: MCP server framework
  • aiosmtplib: Async SMTP client
  • aioimaplib: Async IMAP client
  • email-validator: RFC-compliant email validation
  • Pydantic: Settings management and validation
  • uv: Fast Python package manager

Security Considerations

  • Never commit .env files with real credentials
  • Use App Passwords for Gmail and other providers
  • Store secrets securely in production (Azure Key Vault, etc.)
  • Validate all email addresses before sending
  • Implement rate limiting for production use
  • Use TLS/SSL for all email connections

Troubleshooting

Gmail "Less secure app" error

  • Enable 2FA and use App Passwords instead of your regular password

Connection timeout

  • Check firewall settings
  • Verify server addresses and ports
  • Ensure TLS/SSL settings match your provider

Authentication failed

  • Verify credentials in .env
  • Check if App Password is used (for Gmail)
  • Ensure IMAP/POP3 access is enabled in email settings

License

MIT License - See LICENSE file for details

Contributing

Contributions are welcome! Please open an issue or submit a pull request.

Support

For issues and questions, please open a GitHub issue.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选