Mail MCP Server

1

Add it to Claude Code

Run this in a terminal.

Run in terminal
claude mcp add -e "IMAP_HOST=${IMAP_HOST}" -e "IMAP_PORT=${IMAP_PORT}" -e "EMAIL_USER=${EMAIL_USER}" -e "EMAIL_PASSWORD=${EMAIL_PASSWORD}" -e "SMTP_HOST=${SMTP_HOST}" -e "SMTP_PORT=${SMTP_PORT}" mail-mcp-server -- npx mail-mcp-server
Required:IMAP_HOSTIMAP_PORTEMAIL_USEREMAIL_PASSWORDSMTP_HOSTSMTP_PORT
README.md

Email management via MCP with IMAP and SMTP capabilities.

Mail MCP Server

English | 中文

Email management via MCP (Model Context Protocol). Provides complete IMAP email operations and SMTP sending capabilities through a standardized MCP interface.

Features

  • Folder Management: List, create, delete, rename email folders
  • Email Search: Search with complex IMAP criteria (FROM, TO, SUBJECT, UNSEEN, etc.)
  • Email Operations: Get full email details including body and attachments
  • Mark Operations: Mark as read/unread, flagged/unflagged
  • Move/Copy: Move or copy emails between folders
  • Delete: Delete emails with expunge
  • SMTP Sending: Send emails with attachments, replies, and forwards
    • SSL (465) and STARTTLS (587) support
    • Plain text / HTML dual format
    • File attachments
    • OAuth2 authentication (for Gmail, etc.)

Installation

# Clone and install
cd mail-mcp-server
pip install -e .

# Or install directly
pip install mcp>=1.0.0 pydantic>=2.0.0 python-dotenv>=1.0.0

Configuration

Configure via environment variables:

IMAP Settings

Variable Description Default
IMAP_HOST IMAP server hostname imap.example.com
IMAP_PORT IMAP server port 993
EMAIL_USER Email username -
EMAIL_PASSWORD Email password -
IMAP_SSL Use SSL connection true

SMTP Settings

Variable Description Default
SMTP_HOST SMTP server hostname smtp.example.com
SMTP_PORT SMTP server port 465
EMAIL_USER Email username (same as IMAP) -
EMAIL_PASSWORD Email password (same as IMAP) -
SMTP_SSL Use SSL/TLS (port 465) true
SMTP_STARTTLS Use STARTTLS (port 587) false

Example

# IMAP (阿里云企业邮箱示例)
export IMAP_HOST=mail.qiye.aliyun.com
export IMAP_PORT=993
export EMAIL_USER=your.email@company.com
export EMAIL_PASSWORD=your-password
export IMAP_SSL=true

# SMTP (for sending)
export SMTP_HOST=smtp.qiye.aliyun.com
export SMTP_PORT=465
export SMTP_SSL=true

# Gmail 示例 (需要 App Password)
# export IMAP_HOST=imap.gmail.com
# export SMTP_HOST=smtp.gmail.com
# export EMAIL_PASSWORD=your-app-password

Note: For Gmail, you need to use an App Password.

Usage

As MCP Server

# Run as stdio MCP server
python -m mail_mcp.server

With npx (npm)

# Install and run
npx mail-mcp-server

MCP Tools

Folder Management

`list_folders`

List all email folders.

{
  "name": "list_folders",
  "arguments": {}
}
`create_folder`

Create a new folder.

{
  "name": "create_folder",
  "arguments": {
    "folder_name": "Work/Projects"
  }
}
`delete_folder`

Delete a folder.

{
  "name": "delete_folder",
  "arguments": {
    "folder_name": "Work/Old"
  }
}
`rename_folder`

Rename a folder.

{
  "name": "rename_folder",
  "arguments": {
    "old_name": "Work/Old",
    "new_name": "Work/Archive"
  }
}

Email Operations

`search_emails`

Search emails with IMAP criteria.

{
  "name": "search_emails",
  "arguments": {
    "folder": "INBOX",
    "criteria": "UNSEEN FROM sender@example.com",
    "limit": 10
  }
}

Common Criteria:

  • ALL - All messages
  • UNSEEN - Unread messages
  • SEEN - Read messages
  • FLAGGED - Flagged messages
  • FROM <email> - From specific sender
  • TO <email> - To specific recipient
  • SUBJECT <text> - Subject contains text
  • SINCE <date> - After date (e.g., "14-Mar-2024")
  • BEFORE <date> - Before date
`get_email`

Get detailed email information.

{
  "name": "get_email",
  "arguments": {
    "folder": "INBOX",
    "message_id": "1",
    "uid": "100",
    "include_body": true
  }
}

Note: Provide either message_id or uid.

Mark Operations

`mark_read`

Mark email as read (seen).

{
  "name": "mark_read",
  "arguments": {
    "folder": "INBOX",
    "message_id": "1"
  }
}
`mark_unread`

Mark email as unread.

{
  "name": "mark_unread",
  "arguments": {
    "folder": "INBOX",
    "uid": "100"
  }
}
`mark_flagged`

Mark email as flagged (starred).

{
  "name": "mark_flagged",
  "arguments": {
    "folder": "INBOX",
    "message_id": "1"
  }
}
`unmark_flagged`

Remove flagged status.

{
  "name": "unmark_flagged",
  "arguments": {
    "folder": "INBOX",
    "message_id": "1"
  }
}

Move/Copy Operations

`move_email`

Move email to another folder.

{
  "name": "move_email",
  "arguments": {
    "source_folder": "INBOX",
    "target_folder": "Archive",
    "message_id": "1"
  }
}
`copy_email`

Copy email to another folder.

{
  "name": "copy_email",
  "arguments": {
    "source_folder": "INBOX",
    "target_folder": "Archive",
    "uid": "100"
  }
}

Delete

`delete_email`

Dele

Tools (13)

list_foldersList all email folders.
create_folderCreate a new folder.
delete_folderDelete a folder.
rename_folderRename a folder.
search_emailsSearch emails with IMAP criteria.
get_emailGet detailed email information.
mark_readMark email as read (seen).
mark_unreadMark email as unread.
mark_flaggedMark email as flagged (starred).
unmark_flaggedRemove flagged status.
move_emailMove email to another folder.
copy_emailCopy email to another folder.
delete_emailDelete an email.

Environment Variables

IMAP_HOSTrequiredIMAP server hostname
IMAP_PORTrequiredIMAP server port
EMAIL_USERrequiredEmail username
EMAIL_PASSWORDrequiredEmail password
SMTP_HOSTrequiredSMTP server hostname
SMTP_PORTrequiredSMTP server port

Configuration

claude_desktop_config.json
{"mcpServers": {"mail": {"command": "python", "args": ["-m", "mail_mcp.server"], "env": {"IMAP_HOST": "imap.example.com", "IMAP_PORT": "993", "EMAIL_USER": "user@example.com", "EMAIL_PASSWORD": "password", "SMTP_HOST": "smtp.example.com", "SMTP_PORT": "465"}}}}

Try it

Find all unread emails from my manager in the INBOX.
Move all emails with 'Project X' in the subject from the INBOX to the 'Work' folder.
Get the details and body of the most recent email in my INBOX.
Mark all emails from the last week as read.

Frequently Asked Questions

What are the key features of Mail MCP Server?

Full IMAP folder management including create, delete, and rename.. Advanced email search using complex IMAP criteria.. SMTP support for sending emails with attachments and HTML formatting.. Email organization tools like moving, copying, and marking as read/flagged..

What can I use Mail MCP Server for?

Automating the sorting of incoming emails into specific project folders.. Quickly searching through large email archives using natural language queries.. Programmatically sending status reports or notifications via email.. Managing email inbox hygiene by bulk-marking or deleting messages..

How do I install Mail MCP Server?

Install Mail MCP Server by running: pip install -e .

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