Email MCP Server

Email MCP Server

An MCP server that enables AI models to read, search, and send emails via IMAP and SMTP protocols. It supports various providers like Gmail and Outlook, allowing for tasks such as retrieving unread messages, searching by sender, and managing mailbox folders.

Category
访问服务器

README

Email MCP Server

Email MCP Server

An MCP (Model Context Protocol) server for reading and sending emails via IMAP/SMTP. This server exposes email operations as MCP tools that can be used by Claude and other AI models. Works with Gmail, Outlook, and any email provider that supports IMAP/SMTP.

Features

  • List Emails: Retrieve emails from any mailbox folder
  • Get Unread Emails: Fetch only unread messages
  • Search Emails: Search with IMAP search criteria (e.g., by sender, date, subject)
  • Get Emails from Sender: Retrieve all emails from a specific sender
  • Get Emails by Subject: Search by subject text
  • Send Emails: Compose and send emails via SMTP
  • List Folders: View all available mailbox folders
  • Get Email Details: Fetch complete details of a specific email

Prerequisites

  • Python 3.10 or higher
  • An email account (Gmail, Outlook, etc.) with IMAP/SMTP enabled

Quick Start

1. For Gmail Users

  1. Enable 2-Factor Authentication in your Gmail account: https://myaccount.google.com/security
  2. Generate an "App Password" for Mail: https://myaccount.google.com/apppasswords
  3. Use your Gmail address and the generated app password

2. For Other Email Providers

  • Outlook: Use your Microsoft account password (or create app password if 2FA enabled)
  • Yahoo: Generate an "App Password": https://login.yahoo.com/account/security
  • Other providers: Consult your provider's IMAP/SMTP documentation

3. Installation

# Clone or navigate to the server directory
cd gmail-server

# Install dependencies
pip install -r requirements.txt
# or
pip install -e .

4. Configuration

Create a .env file in the project directory:

Edit .env with your email credentials:

EMAIL_ADDRESS=your_email@gmail.com
EMAIL_PASSWORD=your_app_password_or_password

# Optional: Custom IMAP/SMTP servers
# IMAP_SERVER=imap.gmail.com
# SMTP_SERVER=smtp.gmail.com

5. Run the Server

python gmail_mcp_server.py

The server will start and be ready to use with Claude or other MCP clients.

Available Tools

list_emails

List emails from a folder.

Parameters:

  • max_results (int, default: 10): Number of emails to retrieve
  • unread_only (bool, default: false): Only return unread emails
  • folder (string, default: "INBOX"): Mailbox folder name

Example:

list_emails(max_results=20, unread_only=true, folder="INBOX")

get_unread_emails

Get unread emails from a folder.

Parameters:

  • max_results (int, default: 10): Number of unread emails to retrieve
  • folder (string, default: "INBOX"): Mailbox folder name

get_emails_from_sender

Get emails from a specific sender.

Parameters:

  • sender (string): Email address of the sender
  • max_results (int, default: 10): Number of emails to retrieve
  • folder (string, default: "INBOX"): Mailbox folder name

search_emails

Search emails using IMAP search criteria.

Parameters:

  • query (string): IMAP search query
  • max_results (int, default: 10): Maximum results to return
  • folder (string, default: "INBOX"): Mailbox folder to search

Query Examples:

  • UNSEEN - Unread messages
  • FROM "user@example.com" - Emails from specific sender
  • SUBJECT "invoice" - Emails with "invoice" in subject
  • FLAGGED - Starred/flagged emails
  • UNFLAGGED - Unstarred emails
  • ALL - All emails (default search)
  • BEFORE <date> - Emails before a date (e.g., BEFORE "1-Jan-2024")
  • SINCE <date> - Emails since a date
  • LARGER <bytes> - Emails larger than size

You can combine criteria: UNSEEN FROM "user@example.com" or SUBJECT "urgent" FLAGGED

get_emails_by_subject

Get emails by subject text.

Parameters:

  • subject (string): Subject text to search for
  • max_results (int, default: 10): Maximum emails to retrieve
  • folder (string, default: "INBOX"): Mailbox folder to search

send_email

Send an email.

Parameters:

  • recipient (string): Recipient email address
  • subject (string): Email subject
  • body (string): Email body text
  • html (bool, default: false): If true, body is treated as HTML

get_email_details

Get full details of a specific email.

Parameters:

  • message_id (string): Email ID from IMAP

list_folders

List all available mailbox folders.

Supported Email Providers

Gmail

  • IMAP Server: imap.gmail.com (port 993)
  • SMTP Server: smtp.gmail.com (port 587)
  • Requires: App Password (not your regular Gmail password)

Configuration

The server uses environment variables for configuration:

  • EMAIL_ADDRESS: Your email address (required)
  • EMAIL_PASSWORD: Your password or app password (required)
  • IMAP_SERVER: IMAP server address (default: imap.gmail.com)
  • SMTP_SERVER: SMTP server address (default: smtp.gmail.com)

Usage Example with Claude

You can use this MCP server with Claude by adding it to your Claude configuration. After setting up the server, it will be available as a tool set that Claude can use to read, search, and send emails.

Troubleshooting

"Authentication failed"

  • For Gmail: Make sure you're using an App Password, not your regular Gmail password
  • For other providers: Verify your password is correct
  • Make sure IMAP/SMTP is enabled in your email account settings

"Connection refused"

  • Check your IMAP/SMTP server addresses
  • Verify your email provider's IMAP/SMTP ports
  • Check if your firewall blocks these ports

"Certificate verification failed"

  • This usually happens with corporate firewalls
  • The server uses SSL certificates for secure connections

"No module named 'mcp'"

  • Run: pip install -r requirements.txt

Security Notes

  • Never commit .env file to version control
  • Never hardcode credentials in scripts
  • The server requires your email password - store it safely
  • Use app-specific passwords when available (Gmail, Yahoo, etc.)
  • The server only supports read-only access to IMAP unless you explicitly allow send

File Structure

gmail-server/
├── gmail_mcp_server.py      # Main MCP server implementation
├── gmail_client.py          # IMAP/SMTP email client wrapper
├── pyproject.toml           # Project configuration
├── requirements.txt         # Python dependencies
├── .env.example             # Example environment variables
├── .gitignore              # Git ignore rules
├── setup.py                # Setup validation script
├── mcp-config.json         # MCP configuration example
└── README.md               # This file

License

MIT License

推荐服务器

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选