scorpiox-server-email

Full-stack email server in pure C — SMTP MTA on port 25/587, IMAP4rev1 on port 993, DKIM signing, Maildir storage, TLS via mbedTLS. Zero external dependencies.

SMTP IMAP TLS
Port 25 — MTA relay Port 587 — Submission Port 993 — IMAPS

Overview

scorpiox-server-email is a self-contained email server compiled from a single C source file (scorpiox/scorpiox-server-email.c). It implements a full SMTP Mail Transfer Agent on ports 25 and 587 (submission), an IMAP4rev1 server on port 993 (IMAPS), DKIM signing for outbound messages, Maildir-format storage, and email aliasing — all using mbedTLS for encryption with zero external dependencies.

Source: scorpiox/scorpiox-server-email.c  |  Type: server  |  TLS: mbedTLS

Protocol Support

SMTP — Simple Mail Transfer Protocol

Full MTA implementation supporting both relay (port 25) and submission (port 587). Handles EHLO/HELO handshake, MAIL FROM, RCPT TO, DATA, and QUIT commands. STARTTLS upgrade is supported for encrypted submission.

# SMTP session example telnet mail.example.com 25 EHLO client.example.com 250-mail.example.com 250-STARTTLS 250-AUTH PLAIN LOGIN 250 OK STARTTLS 220 Ready to start TLS AUTH PLAIN AG1lQHNjb3JwaW94Lm5ldABwYXNzd29yZA== 235 Authentication successful

IMAP4rev1 — Internet Message Access Protocol

IMAP server on port 993 (IMAPS — TLS from connection start). Supports standard IMAP commands: LOGIN, SELECT, EXAMINE, FETCH, SEARCH, STORE, COPY, LIST, LSUB, SUBSCRIBE, UNSUBSCRIBE, and LOGOUT. Mail is stored in Maildir format and served directly from disk.

# IMAP session example (over TLS on port 993) openssl s_client -connect mail.example.com:993 a1 LOGIN user@example.com password a1 OK LOGIN completed a2 SELECT INBOX * 42 EXISTS * 0 RECENT a2 OK [READ-WRITE] SELECT completed a3 FETCH 1:* (FLAGS ENVELOPE) a4 LOGOUT

TLS — Transport Layer Security

All TLS operations use mbedTLS (embedded in the binary, no OpenSSL dependency). SMTP supports STARTTLS upgrade on port 587. IMAP uses TLS-from-connect on port 993. Certificates and keys are configured via EMAIL_TLS_CERT and EMAIL_TLS_KEY in scorpiox-env.txt.

Features

📬

Full SMTP MTA

Complete Mail Transfer Agent on port 25 (relay) and port 587 (submission) with STARTTLS support.

📥

IMAP4rev1 Server

Full IMAP server on port 993 (IMAPS). TLS from connection start. Standard mailbox operations.

🔏

DKIM Signing

Outbound messages are DKIM-signed automatically. Improves deliverability and prevents spoofing.

📁

Maildir Storage

Industry-standard Maildir format. One file per message. No database, no corruption on crash.

🔐

AUTH PLAIN/LOGIN

Standard SMTP authentication mechanisms. Credentials verified against the accounts file.

📧

Email Aliasing

Route messages with aliases. Forward addresses to other accounts without separate mailboxes.

🔄

Mail Queue with Retry

Outbound messages are queued and retried automatically on temporary delivery failures.

🔍

Email Filtering

Server-side filtering rules for incoming messages. Route, tag, or reject based on headers.

🖥️

TUI & Daemon Modes

Run interactively with a terminal UI or daemonize for production. PID file management included.

👤

Account Management

File-based account store. Add, remove, and manage email accounts from the CLI.

🔒

mbedTLS Encryption

All TLS via mbedTLS — compiled in, no OpenSSL, no GnuTLS, no shared library dependencies.

Zero Dependencies

Single C file, single binary. No Postfix, no Dovecot, no Exim. Just compile and run.

Configuration

All settings go in scorpiox-env.txt in your project root. The server reads these at startup.

Key Default Description
EMAIL_SMTP_PORT 25 SMTP MTA listening port for inbound relay
EMAIL_SUBMISSION_PORT 587 SMTP submission port (authenticated, STARTTLS)
EMAIL_IMAP_PORT 993 IMAPS port (TLS from connection start)
EMAIL_DOMAIN Primary mail domain (e.g., scorpiox.net)
EMAIL_MAILDIR ./maildir Root directory for Maildir storage
EMAIL_TLS_CERT Path to TLS certificate (PEM format)
EMAIL_TLS_KEY Path to TLS private key (PEM format)
EMAIL_ACCOUNTS_FILE ./accounts.txt File containing user accounts (user:password_hash per line)

Example scorpiox-env.txt

# scorpiox-server-email configuration EMAIL_DOMAIN=scorpiox.net EMAIL_SMTP_PORT=25 EMAIL_SUBMISSION_PORT=587 EMAIL_IMAP_PORT=993 EMAIL_MAILDIR=/var/mail/scorpiox EMAIL_TLS_CERT=/etc/ssl/certs/mail.scorpiox.net.pem EMAIL_TLS_KEY=/etc/ssl/private/mail.scorpiox.net.key EMAIL_ACCOUNTS_FILE=/etc/scorpiox/email-accounts.txt

Usage Examples

Start the email server (daemon mode)

# Start scorpiox-server-email as a daemon sx server-email --daemon # Start in foreground with TUI sx server-email # Check server status sx server-email --status

Account management

# Add a new email account sx server-email --add-account user@scorpiox.net # List all accounts sx server-email --list-accounts # Remove an account sx server-email --remove-account user@scorpiox.net

Send a test email (using scorpiox-email client)

# Send via the local server sx email --to admin@scorpiox.net \ --subject "Test from scorpiox-server-email" \ --body "SMTP server is running." # Send with HTML body from file sx email --to admin@scorpiox.net \ --subject "Report" \ --html-file report.html

DNS records required

# MX record — route mail to your server scorpiox.net. IN MX 10 mail.scorpiox.net. # A record for the mail server mail.scorpiox.net. IN A 203.0.113.10 # SPF — authorize the server to send scorpiox.net. IN TXT "v=spf1 a:mail.scorpiox.net ~all" # DKIM — public key for signature verification sx._domainkey.scorpiox.net. IN TXT "v=DKIM1; k=rsa; p=MIGfMA0..." # DMARC — policy _dmarc.scorpiox.net. IN TXT "v=DMARC1; p=quarantine; rua=mailto:dmarc@scorpiox.net"

Architecture

┌─────────────────────────────────────────────────────────────┐ scorpiox-server-email (single C binary) ├──────────────┬──────────────────┬───────────────────────────┤ SMTP MTA SMTP Submission IMAP4rev1 Server Port 25 Port 587 Port 993 (IMAPS) Relay inbound STARTTLS + AUTH TLS-from-connect ├──────────────┴──────────────────┴───────────────────────────┤ ┌──────────┐ ┌───────────┐ ┌──────┐ ┌──────────────┐ DKIM │ │ Mail Queue│ │ Auth │ │ Email Filter │ Signing │ │ + Retry │ │ PLAIN│ │ Rules Engine │ └──────────┘ └───────────┘ │ LOGIN│ └──────────────┘ └──────┘ ├─────────────────────────────────────────────────────────────┤ mbedTLS — all TLS operations ├─────────────────────────────────────────────────────────────┤ Maildir (one file per message on disk) ~/maildir/user/cur/ ~/maildir/user/new/ .../tmp/ └─────────────────────────────────────────────────────────────┘

Security & TLS

Related: scorpiox-email (Client)

scorpiox-server-email is the server. The corresponding client is scorpiox-email — a lightweight SMTP client built on libcurl that sends mail through any SMTP server, including scorpiox-server-email.

Client Config Key Description
SMTP_HOSTSMTP server hostname (e.g., mail.scorpiox.net)
SMTP_PORTSMTP port (default: 587)
SMTP_USERAuthentication username
SMTP_PASSAuthentication password
SMTP_FROMSender address
SMTP_TLSTLS mode: starttls, ssl, or none