This document outlines security features and considerations for the mail-mcp MCP server.
All IMAP connections require TLS encryption by default. Insecure connections are rejected.
# Per-account (default: true)
MAIL_IMAP_<ACCOUNT>_SECURE=true
# Common IMAP TLS ports
MAIL_IMAP_<ACCOUNT>_PORT=993 # IMAPS (implicit TLS)- TLS certificate verification is enforced
- Hostname verification is performed
- Connection failures occur if certificates cannot be validated
- STARTTLS is not supported; use implicit TLS (IMAPS) on port 993
Passwords are handled with strict secrecy guarantees:
- Passwords are stored using Rust's
SecretStringtype - Passwords are never included in log output
- Passwords are never returned in tool responses
The TOML file stores passwords, client secrets, and refresh tokens in plaintext,
not an encrypted vault. The default location is ~/.mail-mcp/config.toml.
Keep it out of version control, shared directories, and unprotected backups.
The same precautions apply to files selected by --config or MAIL_CONFIG_FILE.
The default file applies to every MCP client on the machine that starts
mail-mcp without --config or MAIL_CONFIG_FILE: each one gets its accounts
and its write settings (write_enabled, drafts_enabled, smtp_write_enabled).
An environment-only client that must not inherit them sets
MAIL_CONFIG_FILE=none. Transport settings are never read from a TOML file, so
the file cannot switch stdio clients to HTTP.
- CLI secret entry uses hidden terminal prompts; secrets are not accepted as command-line arguments or piped answers. A blank secret during editing keeps the stored value.
- On Unix, CLI saves set the file mode to
0600. Newly created configuration directories use0700; existing directory permissions are not changed. Unix modes do not configure Windows ACLs, so restrict access separately there. - Saves preserve comments on retained settings and unrelated account sections.
config initrefuses to overwrite an existing file. Cancelling a prompt writes nothing; a conflicting edit is rejected instead of silently replacing another change. A save that would exceed the 1 MiB limit is refused and the file is left unchanged. - Saves through a symlinked configuration path write to the link's target. The
save lock (
.<file name>.lockbeside the target) must not be a symlink; a symlinked lock path is refused rather than followed. - Account listings and validation report environment override names, not values. TOML parse errors omit source lines that could contain secrets.
accounts removedeletes only a file account. Environment credentials are unaffected and can keep the account available.config validateis offline.accounts testauthenticates and performs read-only checks without sending or changing mail; OAuth token refresh and provider-side access logging can still occur.
Process environment variables override file values, including write gates.
Review an MCP client's env entries when moving accounts to TOML. Implicit
.env discovery is disabled when a TOML file is selected; it is not merged
silently into file-backed configuration. See
configuration precedence
and guided account management.
# Password in environment (never logged)
MAIL_IMAP_DEFAULT_PASS=your-app-password- Use app-specific passwords instead of account passwords when available
- Never commit
.envfiles to version control - Use secure credential managers for production deployments
- Rotate credentials periodically
Destructive operations are disabled by default and require explicit opt-in.
MAIL_IMAP_WRITE_ENABLED=trueWhen MAIL_IMAP_WRITE_ENABLED=false, these tools return errors:
imap_update_message_flags- Add/remove flagsimap_copy_message- Copy messagesimap_move_message- Move messagesimap_delete_message- Delete messages
imap_delete_message requires explicit confirmation regardless of write gating:
{
"account_id": "default",
"message_id": "imap:default:INBOX:12345:42",
"confirm": true // Required literal true
}All potentially large outputs are bounded to prevent resource exhaustion.
{
"body_max_chars": 2000 // Range: 100..20000, default: 2000
}- HTML is sanitized using
ammoniabefore return - Potentially dangerous tags and attributes are stripped
- CSS styles are removed
- JavaScript is completely removed
{
"extract_attachment_text": true,
"attachment_text_max_chars": 10000 // Range: 100..50000, default: 10000
}{
"max_bytes": 200000 // Range: 1024..1000000, default: 200000
}PDF text extraction is limited to attachments ≤ 5MB. Larger attachments are skipped but do not fail the tool call.
All inputs are validated before IMAP operations:
query,from,to,subject: 1..256 charactersaccount_id: 1..64 characters, pattern^[A-Za-z0-9_-]+$mailbox: 1..256 characterslimit: 1..50 messages
- Search text fields must not contain ASCII control characters
- Mailbox names must not contain ASCII control characters
Searches matching more than 20,000 messages are rejected:
Error: invalid input: search matched 25000 messages; narrow filters to at most 20000 results
Resolution: Add tighter filters (last_days, from, subject, date ranges).
All network operations have configurable timeouts:
# Connection establishment
MAIL_IMAP_CONNECT_TIMEOUT_MS=30000 # 30 seconds
# Server greeting
MAIL_IMAP_GREETING_TIMEOUT_MS=15000 # 15 seconds
# Socket operations (idle, read, write)
MAIL_IMAP_SOCKET_TIMEOUT_MS=300000 # 5 minutesTimeouts prevent indefinite hanging and ensure the server remains responsive.
Send tools accept file_path attachments that the server reads from local
disk. Without a restriction, a prompt-injected model could attach any file the
server process can read (SSH keys, cloud credentials, .env files).
Set MAIL_ATTACHMENT_UPLOAD_DIR to confine file_path attachments to one
directory:
MAIL_ATTACHMENT_UPLOAD_DIR=/Users/me/mail-outbox- The directory must exist; the server refuses to start otherwise.
- Each
file_pathis canonicalized (..and symlinks resolved) and must land inside the directory. Symlinks pointing outside are rejected. - Missing and out-of-scope files return the same error, so the check cannot be used to probe for file existence.
- When unset, any readable file may be attached (backwards-compatible default).
This limits what the server itself reads. content_base64 attachments are
still accepted, so a model that can read files through other tools could
still inline them — scope those tools separately.
- Passwords are never logged
- Secret-like keys (
*_PASS,*_TOKEN,*_KEY) are redacted in logs - Message bodies and attachments are not logged
All tool responses include metadata for auditing:
{
"meta": {
"now_utc": "2024-02-26T10:30:45.123Z",
"duration_ms": 245
}
}- Use app passwords: For Gmail, Outlook, and other services, use app-specific passwords rather than account passwords
- Enable 2FA: Require two-factor authentication on email accounts
- Review access logs: Periodically review email account access logs for suspicious activity
- Restrict write access: Keep
MAIL_IMAP_WRITE_ENABLED=falseunless needed - Secure .env files: Ensure
.envfiles have restrictive permissions (chmod 600 .env)
- Principle of least privilege: Run the server with minimal required permissions
- Network isolation: Deploy in isolated network segments where possible
- Regular updates: Keep dependencies and the server updated
- Audit logs: Monitor server logs for unusual patterns or errors
- Rate limiting: Consider implementing additional rate limiting at the infrastructure layer
- Security review: Changes to security-sensitive code should be reviewed
- Dependency auditing: Regularly audit dependencies for vulnerabilities
- Test boundaries: Test input validation and output bounding thoroughly
- Secret management: Never hardcode credentials in code or tests
- No STARTTLS support: Only implicit TLS (IMAPS) is supported
- No certificate pinning: Certificates are validated per standard PKI; custom CA chains are not supported
- No client authentication: Client certificates are not supported
- No encryption at rest: TOML and
.envcredentials are plaintext on disk; file access controls, backup protection, and disk encryption are the operator's responsibility