Overview
The Mail IMAP MCP Server supports multiple IMAP accounts simultaneously. You can configure accounts for Gmail, Outlook, Fastmail, or any IMAP-compatible email service and switch between them seamlessly.Configuration Format
Accounts are configured using environment variables with the patternMAIL_IMAP_{ACCOUNT_ID}_{SETTING}.
Required Settings
Each account requires three essential settings:MAIL_IMAP_{ACCOUNT_ID}_HOST- IMAP server hostnameMAIL_IMAP_{ACCOUNT_ID}_USER- Email usernameMAIL_IMAP_{ACCOUNT_ID}_PASS- App-specific password
Optional Settings
MAIL_IMAP_{ACCOUNT_ID}_PORT- IMAP port (defaults to 993)MAIL_IMAP_{ACCOUNT_ID}_SECURE- Use TLS (defaults to true)
Setting Up Multiple Accounts
Define your default account
The default account is used when no
account_id is specified in tool calls.Using Multiple Accounts
List All Configured Accounts
Use theimap_list_accounts tool to see all available accounts without exposing credentials:
Specify Account in Tool Calls
All tools accept an optionalaccount_id parameter. When omitted, the default account is used.
Search work email
Search work email
List personal mailboxes
List personal mailboxes
Get message from default account
Get message from default account
The
account_id can be omitted to use the default account:Cross-Account Operations
Copy Messages Between Accounts
You can copy messages from one account to another using theimap_copy_message tool:
- Fetches the raw RFC822 message from the source account
- Connects to the destination account
- Uses IMAP
APPENDto create the message in the destination mailbox
Common Provider Settings
Gmail
Gmail
Host:
Port:
App Password: Generate here
imap.gmail.comPort:
993App Password: Generate here
Outlook/Office 365
Outlook/Office 365
Host:
Port:
Setup: Enable IMAP
outlook.office365.comPort:
993Setup: Enable IMAP
Fastmail
Fastmail
Host:
Port:
App Password: Generate here
imap.fastmail.comPort:
993App Password: Generate here
iCloud Mail
iCloud Mail
Host:
Port:
App Password: Generate here
imap.mail.me.comPort:
993App Password: Generate here
Security Considerations
Password Storage
Passwords configured via environment variables:- Are never logged by the server
- Are never returned in tool responses
- Should use app-specific passwords, not your main account password
Account Isolation
Each account maintains:- Independent IMAP sessions
- Separate authentication
- Isolated connection pools
Troubleshooting
Account not found error
Account not found error
Error:
not found: account 'xyz' not configuredSolution: Ensure environment variables use the exact account ID:- Check spelling and capitalization
- Verify all three required variables are set (
HOST,USER,PASS)
Authentication failed
Authentication failed
Error:
authentication failed: [AUTHENTICATIONFAILED]Solution:- Use app-specific password, not your account password
- Verify IMAP access is enabled for the account
- Check username format (some providers require full email)
Connection timeout
Connection timeout
Error:
operation timed out: tcp connect timeoutSolution:- Verify the IMAP host and port are correct
- Check network/firewall allows connections to port 993
- Increase timeout:
MAIL_IMAP_CONNECT_TIMEOUT_MS=60000
Next Steps
Search Messages
Learn how to search and filter messages across accounts
Error Handling
Understand error responses and recovery strategies