Overview
The Mail IMAP MCP Server discovers accounts by scanning environment variables following the patternMAIL_IMAP_<ACCOUNT>_HOST. Each account requires host, user, and password credentials.
Single Account Setup
For a single account, use theDEFAULT account identifier:
DEFAULT account is normalized to default as the account ID in tool calls.
Multiple Accounts
Configure multiple IMAP accounts with unique identifiers:Required Variables
These environment variables are required for each account:IMAP server hostname (e.g.,
imap.gmail.com, outlook.office365.com)Username for authentication (typically the email address)
Password for authentication
Optional Variables
These environment variables are optional with sensible defaults:IMAP server port. Standard IMAPS port is 993 for implicit TLS.
Whether to use TLS encryption. Currently enforced to
true.Only implicit TLS (IMAPS) on port 993 is supported. STARTTLS is not supported.
Account ID Rules
- Pattern:
^[A-Z0-9_]+$in environment variables (uppercase) - Normalized: Converted to lowercase for use in tool calls (except
DEFAULTbecomesdefault) - Length: 1-64 characters
- Must be unique across all configured accounts
Examples
| Environment Variable Segment | Normalized Account ID |
|---|---|
DEFAULT | default |
WORK | work |
PERSONAL | personal |
BACKUP | backup |
ARCHIVE_2024 | archive_2024 |
Account Discovery
The server automatically discovers accounts by scanning forMAIL_IMAP_*_HOST variables at startup:
- Scans all environment variables
- Finds patterns matching
MAIL_IMAP_<SEGMENT>_HOST - Extracts the
<SEGMENT>as the account identifier - Loads corresponding
USER,PASS,PORT, andSECUREvariables
DEFAULT account.
Common Providers
Gmail
Gmail requires app-specific passwords when 2FA is enabled.
Outlook / Office 365
Fastmail
iCloud
iCloud requires app-specific passwords when 2FA is enabled.
Security Best Practices
- Use app-specific passwords instead of account passwords when available
- Enable 2FA on your email accounts
- Secure .env files with restrictive permissions:
chmod 600 .env - Use credential managers for production deployments
- Rotate credentials periodically
Troubleshooting
Account Not Found
Missing Required Variables
HOST, USER, PASS) for the account.
Authentication Failed
- Verify
USERandPASSare correct - Use app-specific password for Gmail/Outlook/iCloud
- Check that the account allows IMAP access
- Ensure account is not locked or requiring 2FA challenge