loading…
Search for a command to run...
loading…
MCP server for IMAP/SMTP email access with environment-based configuration
MCP server for IMAP/SMTP email access with environment-based configuration
Language: English | 中文
A Model Context Protocol server for IMAP/SMTP email operations with Claude, Cursor, and other AI assistants.
Fixed
search() wrapping criteria in an extra array, breaking compound search conditionsdeleteMessage() failing silently when the mailbox was opened in read-only modegetRecentMessages() misusing the IMAP RECENT flag; now fetches latest N messages by UIDgetRecentMessages() / getUnseenMessages() relying on leftover mailbox state from previous operationscleanReplySubject() only stripping one Re: prefix layer, causing false negatives in unreplied detectionnew Date() parsing across platforms; changed to ISO 8601ensureIMAPConnection() having no timeout while waiting for concurrent initializationsaveSentMessage() always returning sentFolderSaved: true even when save failedhandleGetMessages() / handleDeleteMessage() relying on currentBox state to locate messagesreply_to_email writing literal "undefined" into the body when text is emptyAdded
inboxOnly parameter to restrict search to INBOX onlyImproved
ensureSMTPConnection() now has concurrency guard with 30-second timeout, consistent with IMAP\Sent special-use attribute with result caching, compatible with all mail providerssaveMessageToFolder() simplified; skips saving if no sent folder is foundslice(-limit) to fetch the newest messages first, preventing empty results after date filteringFor the full version history, see CHANGELOG.md.
npm install -g mcp-mail-serverAdd to your claude_desktop_config.json:
{
"mcpServers": {
"mcp-mail-server": {
"command": "npx",
"args": ["-y", "mcp-mail-server"],
"env": {
"IMAP_HOST": "your-imap-server.com",
"IMAP_PORT": "993",
"IMAP_SECURE": "true",
"SMTP_HOST": "your-smtp-server.com",
"SMTP_PORT": "465",
"SMTP_SECURE": "true",
"EMAIL_USER": "[email protected]",
"EMAIL_PASS": "your-password"
}
}
}
}
Add to your Cursor MCP settings:
{
"mcpServers": {
"mcp-mail-server": {
"command": "npx",
"args": ["-y", "mcp-mail-server"],
"env": {
"IMAP_HOST": "your-imap-server.com",
"IMAP_PORT": "993",
"IMAP_SECURE": "true",
"SMTP_HOST": "your-smtp-server.com",
"SMTP_PORT": "465",
"SMTP_SECURE": "true",
"EMAIL_USER": "[email protected]",
"EMAIL_PASS": "your-password"
}
}
}
}
Add using the claude mcp add command:
claude mcp add mcp-mail-server \
-e IMAP_HOST=your-imap-server.com \
-e IMAP_PORT=993 \
-e IMAP_SECURE=true \
-e SMTP_HOST=your-smtp-server.com \
-e SMTP_PORT=465 \
-e SMTP_SECURE=true \
-e [email protected] \
-e EMAIL_PASS=your-password \
-- npx -y mcp-mail-server
Or manually add to .claude/settings.json:
{
"mcpServers": {
"mcp-mail-server": {
"command": "npx",
"args": ["-y", "mcp-mail-server"],
"env": {
"IMAP_HOST": "your-imap-server.com",
"IMAP_PORT": "993",
"IMAP_SECURE": "true",
"SMTP_HOST": "your-smtp-server.com",
"SMTP_PORT": "465",
"SMTP_SECURE": "true",
"EMAIL_USER": "[email protected]",
"EMAIL_PASS": "your-password"
}
}
}
}
Add to codex.json in your project root:
{
"mcpServers": {
"mcp-mail-server": {
"command": "npx",
"args": ["-y", "mcp-mail-server"],
"env": {
"IMAP_HOST": "your-imap-server.com",
"IMAP_PORT": "993",
"IMAP_SECURE": "true",
"SMTP_HOST": "your-smtp-server.com",
"SMTP_PORT": "465",
"SMTP_SECURE": "true",
"EMAIL_USER": "[email protected]",
"EMAIL_PASS": "your-password"
}
}
}
}
Other MCP clients can be configured similarly. The core configuration is:
{
"mcpServers": {
"mcp-mail-server": {
"command": "npx",
"args": ["-y", "mcp-mail-server"],
"env": {
"IMAP_HOST": "your-imap-server.com",
"IMAP_PORT": "993",
"IMAP_SECURE": "true",
"SMTP_HOST": "your-smtp-server.com",
"SMTP_PORT": "465",
"SMTP_SECURE": "true",
"EMAIL_USER": "[email protected]",
"EMAIL_PASS": "your-password"
}
}
}
}
Refer to your specific client's documentation for the appropriate configuration file location.
| Tool | Description |
|---|---|
connect_all |
Connect to both IMAP and SMTP servers |
get_connection_status |
Check connection status and server info |
disconnect_all |
Disconnect from all servers |
open_mailbox |
Open specific mailbox/folder |
list_mailboxes |
List available mail folders |
get_message_count |
Get total message count in current mailbox |
get_unseen_messages |
Get all unread emails |
get_recent_messages |
Get recent emails |
search_by_sender |
Find emails from specific sender |
search_by_subject |
Search by subject keywords |
search_by_recipient |
Find emails sent to specific recipient |
search_by_body |
Search message body content |
search_since_date |
Find emails since date |
search_unread_from_sender |
Find unread emails from specific sender |
search_unreplied_from_sender |
Find unreplied emails from specific sender |
search_with_keyword |
Search emails by keyword/flag |
search_all_messages |
Search all messages with optional date range and limit |
get_message |
Retrieve email by UID |
get_messages |
Retrieve multiple emails |
delete_message |
Delete email by UID |
send_email |
Send email via SMTP (with optional attachments) |
reply_to_email |
Reply to specific email |
get_attachments |
Get attachment metadata for an email |
save_attachment |
Download and save attachments to local files |
mailboxName (string, default: "INBOX"), readOnly (boolean)sender (string, email address), startDate (string, optional), endDate (string, optional)subject (string, keywords), startDate (string, optional), endDate (string, optional)recipient (string, email address), startDate (string, optional), endDate (string, optional)text (string, search text), startDate (string, optional), endDate (string, optional)date (string, date format)sender (string, email address), startDate (string, optional), endDate (string, optional)sender (string, email address), startDate (string, optional), endDate (string, optional), limit (number, optional)keyword (string, keyword), startDate (string, optional), endDate (string, optional)startDate (string, optional), endDate (string, optional), limit (number, optional, default: 50)uid (number), markSeen (boolean, optional)uids (array), markSeen (boolean, optional)uid (number)to (string), subject (string), text (string, optional), html (string, optional), cc (string, optional), bcc (string, optional), attachments (string[], optional, absolute file paths)originalUid (number), text (string), html (string, optional), replyToAll (boolean, optional), includeOriginal (boolean, optional)uid (number) — Returns metadata: filename, contentType, size, indexuid (number), savePath (string, absolute path), attachmentIndex (number, optional, 0-based), returnBase64 (boolean, optional, default: false)Use natural language commands with your AI assistant:
⚠️ All variables are required
| Variable | Description | Example |
|---|---|---|
IMAP_HOST |
IMAP server address | imap.gmail.com |
IMAP_PORT |
IMAP port number | 993 |
IMAP_SECURE |
Enable TLS | true |
SMTP_HOST |
SMTP server address | smtp.gmail.com |
SMTP_PORT |
SMTP port number | 465 |
SMTP_SECURE |
Enable SSL | true |
EMAIL_USER |
Email username | [email protected] |
EMAIL_PASS |
Email password/app password | your-app-password |
IMAP_HOST=imap.gmail.com
IMAP_PORT=993
IMAP_SECURE=true
SMTP_HOST=smtp.gmail.com
SMTP_PORT=465
SMTP_SECURE=true
[email protected]
EMAIL_PASS=your-app-password
Note: Use App Passwords instead of your regular password.
IMAP_HOST=outlook.office365.com
IMAP_PORT=993
IMAP_SECURE=true
SMTP_HOST=smtp.office365.com
SMTP_PORT=587
SMTP_SECURE=true
[email protected]
EMAIL_PASS=your-password
Clone the repository:
git clone https://github.com/yunfeizhu/mcp-mail-server.git
cd mcp-mail-server
Install dependencies:
npm install
Build the project:
npm run build
Set environment variables:
export IMAP_HOST=your-imap-server.com
export IMAP_PORT=993
export IMAP_SECURE=true
export SMTP_HOST=your-smtp-server.com
export SMTP_PORT=465
export SMTP_SECURE=true
export [email protected]
export EMAIL_PASS=your-password
Run the server:
npm start
Contributions are welcome! Please feel free to submit a Pull Request.
MIT License - see LICENSE file for details.
Package Information:
mcp-mail-serverДобавь это в claude_desktop_config.json и перезапусти Claude Desktop.
{
"mcpServers": {
"mail-server": {
"command": "npx",
"args": [
"-y",
"mcp-mail-server"
]
}
}
}