Overview
rmail is a self-contained mail server implemented entirely in the Python 3 standard library. It exposes SMTP (ports 25, 465, 587), IMAP4rev1 (ports 143, 993), and an Exchange-style JSON/HTTP API (ports 9002, 9003) from a single process. Storage uses a Maildir-inspired shard-based filesystem layout that requires no database and supports concurrent access without per-mailbox locks.
- SMTP with EHLO, AUTH PLAIN/LOGIN, STARTTLS, SMTPS (port 465), relay prevention, FROM spoofing detection, SIZE enforcement, and per-IP rate limiting.
- IMAP4rev1 with LOGIN, AUTHENTICATE PLAIN, SELECT, EXAMINE, LIST (wildcard and partial patterns), FETCH, STORE, APPEND, EXPUNGE, UID, COPY, MOVE, SEARCH, IDLE, RENAME, NAMESPACE, ID, ENABLE, UNSELECT, STARTTLS, LITERAL+.
- TLS security model: AUTH capabilities hidden on cleartext connections when TLS is configured, requiring STARTTLS before credential transmission.
- Exchange-style REST API with stateless JWT authentication, CORS support, admin-only alias management, Thunderbird/Outlook autoconfig, and pagination.
- Shard-based storage: metadata encoded in filenames, lock-free flag operations via atomic
os.rename(). - Auto-generated self-signed TLS certificates; CA-signed certificates supported via config.
- Per-domain regex alias routing with exact-match priority and catch-all support.
- Per-user storage quotas enforced on all append paths (SMTP, IMAP APPEND, Exchange API).
- Multi-worker async delivery queue with configurable worker count.
- PBKDF2-SHA256 password hashing with 300,000 iterations; admin flag and account disable support.
- Input validation on all protocol boundaries via a built-in validation framework.
- Zero third-party dependencies — Python 3.8+ stdlib only.
- Systemd service integration with automatic restart on failure.
- 8-phase diagnostic tool and end-to-end test suite included.
- Curses terminal IMAP/SMTP client included.
Documentation
Getting Started
Installation, initial configuration, and first-run instructions.
Usage
SMTP, IMAP, and Exchange API usage with concrete examples.
Architecture
Module layout, data flow, storage design, and concurrency model.
Configuration
All configuration keys, defaults, rate limiting, and TLS options.
Advanced
Scaling, multi-process deployment, diagnostics, and signal handling.
Quick Start
git clone <repo> rmail
cd rmail
python run.py init # generate config.json
python run.py # start server
make user # create a user account
The server auto-generates a self-signed TLS certificate on first startup.
Edit config.json to set your hostname and accepted domains before creating users.