A unified MCP email service supporting multi-account management with AI-powered intelligent monitoring and notifications.
New Feature: Email translation & summarization with n8n automation - automatically translate non-Chinese emails, generate summaries, and send to Feishu/Lark!
Automatically monitor emails, filter important ones with AI, and send real-time notifications to your team chat!
- AI Smart Filtering: Uses OpenAI/Claude to intelligently identify important emails
- Multi-platform Notifications: Supports Feishu/DingTalk/WeChat Work/Slack
- Automated Monitoring: n8n workflow runs every 5 minutes automatically
- Deduplication: Prevents duplicate notifications
- Production Ready: Comprehensive error handling and fallback mechanisms
# 1. Set up the monitoring system
python scripts/setup_n8n_monitoring.py
# 2. Configure environment variables
export FEISHU_WEBHOOK="your_webhook_url"
export OPENAI_API_KEY="your_api_key" # Optional for AI filtering
# 3. Import n8n workflow
# Import n8n/email_monitoring_workflow.json in your n8n instance
# 4. Start monitoring!
# The system will automatically check emails every 5 minutesDocumentation: See N8N_EMAIL_MONITORING_GUIDE.md for complete setup guide.
- 163 Mail (mail.163.com / mail.126.com)
- QQ Mail (mail.qq.com)
- Gmail (mail.google.com)
- Outlook/Hotmail
- Custom IMAP servers
npx -y @smithery/cli install mcp-email-service --client claudeAfter installation, you'll need to configure your email accounts:
cd ~/.config/smithery/servers/mcp-email-service
python setup.pyRequires Python 3.11+ and UV.
git clone https://github.com/leeguooooo/email-mcp-service.git
cd email-mcp-service
uv sync# Interactive setup
uv run python setup.py
# Or manually copy example config
cp examples/accounts.example.json accounts.json
# Then edit accounts.json with your email settings| Provider | Configuration Steps |
|---|---|
| 163 Mail | Login to mail.163.com → Settings → Enable IMAP → Get authorization code (use code, not password) |
| QQ Mail | Settings → Account → Enable IMAP → Generate authorization code |
| Gmail | Enable 2FA → Generate app password |
| Outlook | Use email password directly |
If you installed manually, add to your MCP client (e.g., Claude Desktop) config:
{
"mcpServers": {
"mcp-email-service": {
"command": "/your/path/mcp-email-service/run.sh",
"args": []
}
}
}list_emails # View unread emails
list_emails with unread_only=false # View all emails
list_emails with limit=100 # View more emailssearch_emails with query="meeting" # Search emails containing "meeting"
search_emails with query="john" search_in="from" # Search by sender
search_emails with date_from="2024-01-01" # Search by dateget_email_detail with email_id="123" # View email details
mark_emails with email_ids=["123"] mark_as="read" # Mark as read
delete_emails with email_ids=["123"] # Delete email
flag_email with email_id="123" set_flag=true # Add starsend_email with to=["user@example.com"] subject="Subject" body="Content"
reply_email with email_id="123" body="Reply content"analyze_contacts # Analyze top contacts (last 30 days)
analyze_contacts with days=90 limit=20 # Customize analysis period
analyze_contacts with group_by="sender" # Analyze only senders
get_contact_timeline with contact_email="user@example.com" # Get communication timelinelist_emails- List emailsget_email_detail- View email detailssearch_emails- Search emailsmark_emails- Mark as read/unreaddelete_emails- Delete emailsflag_email- Star/unstar emailssend_email- Send new emailreply_email- Reply to emailforward_email- Forward emailmove_emails_to_folder- Move emailslist_folders- View foldersget_email_attachments- Get attachmentscheck_connection- Test connectionsanalyze_contacts⭐ - Analyze contact frequencyget_contact_timeline⭐ - Get communication timeline
The AI monitoring system includes several powerful scripts:
scripts/call_email_tool.py- Bridge between n8n and MCP toolsscripts/ai_email_filter.py- AI-powered email importance filteringscripts/notification_service.py- Multi-platform notification servicescripts/email_monitor.py- Main monitoring controllerscripts/setup_n8n_monitoring.py- Automated setup script
# Test email fetching
python scripts/call_email_tool.py list_unread_emails '{"limit":5}'
# Test AI filtering
python scripts/ai_email_filter.py '[{"id":"test","subject":"Urgent meeting","from":"boss@company.com","date":"2024-01-15","body_preview":"Important project discussion..."}]'
# Test notifications
python scripts/notification_service.py test
# Run complete monitoring cycle
python scripts/email_monitor.py run
# Check system status
python scripts/email_monitor.py status- Feishu/Lark - Rich card notifications with interactive elements
- DingTalk - Markdown formatted messages with @mentions
- WeChat Work - Styled messages with color coding
- Slack - Block-based rich formatting
- Custom Webhooks - Flexible JSON payload support
- Login Failed: 163/QQ Mail use authorization codes, Gmail uses app passwords
- Can't Find Emails: Default shows unread only, use
unread_only=false - Connection Timeout: Check network and firewall settings
- AI Filtering Failed: System automatically falls back to keyword filtering if AI API fails
- Webhook Not Working: Verify webhook URL and test with
python scripts/test_lark_webhook.py - n8n Workflow Errors: Check environment variables (
FEISHU_WEBHOOK,OPENAI_API_KEY) - Script Permission Denied: Run
chmod +x scripts/*.pyto make scripts executable - No Notifications: Check notification config and test with
python scripts/notification_service.py test
# Check system status
python scripts/email_monitor.py status
# Test all components
python scripts/setup_n8n_monitoring.py --test-only
# View logs
tail -f email_monitor.log
# Check environment variables
env | grep -E "(FEISHU|OPENAI|PYTHONPATH)"mcp-email-service/
├── data/ # Runtime data directory (auto-created)
│ ├── email_sync.db # Email synchronization database
│ ├── sync_config.json # Sync configuration
│ ├── logs/ # Log files
│ ├── tmp/ # Temporary files
│ └── attachments/ # Downloaded attachments
├── src/ # Source code
│ ├── config/ # Configuration management
│ │ └── paths.py # Centralized path configuration
│ ├── operations/ # Email operations
│ ├── background/ # Background sync scheduler
│ └── ...
├── tests/ # Test suite (71/72 passing)
├── docs/ # Documentation
│ ├── guides/ # User guides
│ └── archive/ # Historical documents
├── scripts/ # Utility scripts
├── n8n/ # n8n workflow templates
├── config_templates/ # Configuration examples
└── accounts.json # Email account configuration (user-created)
- Auto-start Background Sync: Synchronization starts automatically with MCP server
- Centralized Data Management: All runtime data in
data/directory - UID-based Operations: Stable email identification across operations
- Smart Caching: 100-500x faster than live IMAP queries
- Multi-account Support: Manage multiple email accounts with proper isolation
- Performance Optimized: Shared connections for batch operations (5x faster)
- Well Tested: 71/72 tests passing, ~65% code coverage
- docs/guides/EMAIL_TRANSLATE_WORKFLOW_GUIDE.md - Email translation & summarization workflow
- docs/guides/HTTP_API_QUICK_START.md - HTTP API quick start
- docs/guides/N8N_EMAIL_MONITORING_GUIDE.md - n8n email monitoring guide
- docs/guides/LARK_SETUP_GUIDE.md - Feishu/Lark webhook setup
- docs/guides/FINAL_DEPLOYMENT_CHECKLIST.md - Deployment checklist
- docs/guides/PRODUCTION_DEPLOYMENT_GUIDE.md - Production deployment guide
- docs/guides/SECURITY_SETUP_GUIDE.md - Security configuration
- docs/README.md - Complete documentation index
- docs/ARCHITECTURE.md - System architecture and design
- docs/database_design.md - Database schema and design
- n8n/README.md - n8n workflow details
- config_templates/ - Configuration templates and examples
- data/README.md - Data directory usage guide
If you find this project helpful, please consider:
- Star this repository to show your support
- Report bugs or suggest features via Issues
- Contribute code or documentation via Pull Requests
- Sponsor the development via GitHub Sponsors
If you'd like to support this project, you can use WeChat Pay or Alipay:
Your support helps maintain and improve this project! Thank you!
We welcome contributions! Please feel free to submit issues and pull requests.
# Clone the repository
git clone https://github.com/leeguooooo/email-mcp-service.git
cd email-mcp-service
# Install dependencies (including dev tools)
uv sync --extra dev
# Run tests
uv run pytest
# Set up development environment
cp config_templates/env.n8n.example .env
# Edit .env with your configuration# Run all tests
uv run pytest
# Run specific test file
uv run pytest tests/test_mcp_tools.py
# Run with coverage
uv run pytest --cov=src --cov-report=htmlOption 1: Install dev dependencies (recommended)
# Install with dev extras (includes black, ruff, mypy)
uv sync --extra dev
# Then run tools
uv run black src/ scripts/ tests/
uv run ruff check src/ scripts/ tests/
uv run mypy src/Option 2: Use uv tool (no installation needed)
# Format code
uvx black src/ scripts/ tests/
# Lint code
uvx ruff check src/ scripts/ tests/
# Type check
uvx mypy src/- Multi-account email management
- AI-powered email filtering
- Email translation & summarization (OpenAI)
- Multi-platform notifications
- n8n workflow automation
- Production-ready error handling
- Email auto-reply with AI
- Smart email categorization
- Advanced analytics dashboard
- Mobile app notifications
All sensitive endpoints are protected with API key authentication. See SECURITY_SETUP_GUIDE.md for details.
Never commit sensitive information. Always use environment variables:
.envfiles are automatically ignored by git- Use
.env.exampletemplates for documentation - Rotate API keys regularly
Please report security vulnerabilities to the repository maintainers privately before public disclosure.
This project is licensed under the MIT License - see the LICENSE file for details.