tawsil (توصيل) is a minimal SMTP relay written in Rust. It accepts incoming SMTP messages and forwards them to a local sendmail-compatible MTA (such as nullmailer or msmtp). It is designed for simple mail relay on Linux servers.
In a Docker context, tawsil is useful as a lightweight SMTP gateway for containers that need to send email (e.g., web apps, cron jobs, monitoring tools) but do not include a full MTA. By running tawsil as a sidecar or service container, you can centralize outgoing mail handling, deduplicate messages, and forward them to a real MTA or mail relay, keeping your application containers minimal and secure.
tawsil implements the core SMTP protocol as described in RFC 5321, handling basic commands like HELO, MAIL FROM, RCPT TO, DATA, and QUIT. It does not implement advanced features (such as authentication, TLS, or extended SMTP commands), so it is compliant with the minimal requirements of RFC 5321 for simple message relay, but not with extensions from RFC 5322, RFC 4954 (AUTH), or RFC 3207 (STARTTLS).
- Minimal SMTP server: Handles basic SMTP commands (
HELO,MAIL FROM,RCPT TO,DATA, etc.). - Deduplication: Suppresses duplicate emails within a 10-minute window using SHA-256 hashing.
- Integration: Forwards mail to a local
sendmail-compatible binary. - Systemd-ready: Includes a
Makefilefor installation andsystemdservice setup. - Logging: Logs all SMTP transactions with timestamps.
tawsil is designed to be used in controlled environments, such as internal networks or as a sidecar in Docker setups. It must not be exposed to the public internet.
If you bind tawsil to a public interface (e.g., 0.0.0.0), it will act as an open relay, allowing anyone to send email through your server.
Always bind tawsil to a private interface or use firewall rules to restrict access.
The program does not implement authentication or access controls and is intentionally minimal to reduce attack surface, but this also means it relies on network-level security.
- Rust toolchain (
cargo,rustc) - A local
sendmail-compatible MTA (e.g.,nullmailer,msmtp) - Linux system with
systemd
makeRun as root or with sudo:
sudo make installThis will:
- Install the binary to
/opt/tawsil - Copy
.envif present - Set up a
systemdservice
sudo make uninstallCreate a .env file in the project root or in /opt/tawsil with the following variables:
SMTP_HOST=0.0.0.0
SMTP_PORT=2525
SENDMAIL_PATH=/usr/sbin/sendmailSMTP_HOST: Address to bind (default: 0.0.0.0) SMTP_PORT: Port to listen on (default: 2525) SENDMAIL_PATH: Path to the sendmail-compatible binary
- Listens for SMTP connections.
- Accepts and parses SMTP commands.
- On
DATA, collects the message and checks for duplicates. - Forwards unique messages to the configured sendmail binary.
- Logs all actions and responses.