rmail

Production-grade mail server stack in pure Python 3 asyncio — SMTP, IMAP4rev1, outbound relay, and Exchange HTTP API.

Configuration File

rmail reads config.json from the working directory on startup. Generate a default file with all options:

python run.py init

An alternative path can be passed directly:

python run.py /etc/rmail/config.json
All values have defaults. Missing keys fall back to the default silently. Invalid values (wrong type or out of range) emit a warning and fall back to the default.

Top-Level

KeyDefaultDescription
hostnamemail.example.comServer FQDN. Used in SMTP banners, EHLO, DSN bounces, autoconfig.
mail_root./mailstoreRoot directory for all mail storage.
domains["example.com"]List of locally hosted domains. SMTP accepts recipients in these domains.
log_levelINFOLogging verbosity: DEBUG, INFO, WARNING, ERROR, CRITICAL.

SMTP

KeyDefaultDescription
smtp.host0.0.0.0Bind address for all SMTP ports.
smtp.port25Standard SMTP port (inbound from other mail servers).
smtp.submission_port587Authenticated submission port.
smtp.smtps_port465SMTPS port (implicit TLS).
smtp.max_recipients50Maximum RCPT TO per message.
smtp.max_connections100Maximum simultaneous SMTP connections across all ports.
smtp.max_messages_per_connection50Maximum messages sent per persistent connection.
smtp.max_message_size52428800Maximum message size in bytes (50 MiB).

IMAP

KeyDefaultDescription
imap.host0.0.0.0Bind address.
imap.port143IMAP port.
imap.imaps_port993IMAPS port (implicit TLS).
imap.max_connections100Maximum simultaneous IMAP connections.

Exchange API

KeyDefaultDescription
exchange_api.host0.0.0.0Bind address.
exchange_api.port9002HTTP API port.
exchange_api.secure_port9003HTTPS API port (implicit TLS).
exchange_api.token_secretauto-generatedHMAC-SHA256 key for JWT tokens. Auto-generated and written to config on first start if null.

Delivery

KeyDefaultDescription
delivery.workers4Async worker count for the local delivery queue.
delivery.max_queue_size1000Maximum messages in the local delivery queue. 0 = unlimited.

Outbound Relay

Relay only applies to authenticated users. Unauthenticated senders to external domains are always rejected regardless of this configuration.
KeyDefaultDescription
relay.enabledtrueAllow authenticated users to send to external domains.
relay.workers2Async worker count for the relay queue.
relay.max_queue_size500Maximum messages in the relay queue. 0 = unlimited.
relay.connect_timeout30TCP connect timeout in seconds for outbound connections.
relay.command_timeout60Timeout in seconds for individual SMTP commands.
relay.data_timeout300Timeout in seconds for DATA transmission.
relay.max_retries8Total delivery attempts before generating a DSN bounce.
relay.smarthost""Smarthost address. Empty string = direct MX delivery.
relay.smarthost_port587Smarthost port.
relay.smarthost_username""AUTH PLAIN username for smarthost. Empty = no authentication.
relay.smarthost_password""AUTH PLAIN password for smarthost.

Retry schedule (delays between attempts): 1m, 5m, 15m, 30m, 1h, 4h, 8h, 24h. Total window approximately 37.5 hours.

TLS

KeyDefaultDescription
tls.cert_filenullPath to PEM certificate. If null, a self-signed cert is auto-generated at {mail_root}/tls/cert.pem.
tls.key_filenullPath to PEM private key. If null, auto-generated at {mail_root}/tls/key.pem.
When TLS is configured, AUTH mechanisms are hidden from cleartext EHLO/CAPABILITY responses. Clients must perform STARTTLS before credentials are accepted. Auto-generated certificates are self-signed and will trigger warnings in strict clients.

Rate Limiting

KeyDefaultDescription
rate_limit.enabledtrueEnable per-IP rate limiting.
rate_limit.connection_rate20New connections allowed per IP per connection_period.
rate_limit.connection_period60Window in seconds for connection rate tracking.
rate_limit.message_rate30Messages allowed per IP per message_period.
rate_limit.message_period60Window in seconds for message rate tracking.
rate_limit.recipient_rate100RCPT TO commands allowed per IP per recipient_period.
rate_limit.recipient_period60Window in seconds for recipient rate tracking.
rate_limit.auth_failure_limit5Auth failures before IP lockout.
rate_limit.auth_failure_lockout600Lockout duration in seconds after exceeding auth failure limit.
rate_limit.max_concurrent_per_ip10Maximum simultaneous connections per IP.
rate_limit.whitelist["127.0.0.1","::1"]IPs exempt from all rate limiting.
rate_limit.max_tracked_ips10000Maximum IPs tracked in memory.
rate_limit.cleanup_interval300Seconds between cleanup sweeps of expired tracking entries.

Minimal Production Example

{
  "hostname": "mail.yourdomain.com",
  "mail_root": "/var/mail/rmail",
  "domains": ["yourdomain.com"],
  "log_level": "INFO",
  "smtp": {
    "max_message_size": 52428800
  },
  "relay": {
    "enabled": true,
    "workers": 2
  },
  "tls": {
    "cert_file": "/etc/ssl/certs/mail.pem",
    "key_file": "/etc/ssl/private/mail.key"
  },
  "rate_limit": {
    "enabled": true,
    "whitelist": ["127.0.0.1", "::1"]
  }
}