LSMTPD Documentation
website·Indexed 30 days ago
https://lsmtp.nekonik.orgA lightweight and high-performance SMTP server designed to bridge email and message queues, featuring seamless AMQP integration. Built with the Rust toolchain, it is optimized for containers, VMs, and microservices architectures, enabling event-driven email processing by placing email messages into RabbitMQ queues.
What's inside LSMTPD
- LSMTPD is a minimal and efficient SMTP server designed for low resource consumption, making it suitable for deployment in containers, virtual machines (VMs), and microservices. Its primary functionality is to integrate SMTP traffic with AMQP message brokers, converting incoming emails into actionable events for downstream systems. The project is open source, allowing for code inspection and community contribution.
Overview of LSMTPD
LSMTPD (Lightweight SMTP Daemon) is a high-performance, minimalistic SMTP server written in Rust. Its primary purpose is to act as a bridge between email and message queues by accepting incoming SMTP email messages and forwarding them directly into AMQP (Advanced Message Queuing Protocol) systems. It is designed for distributed systems and microservices that need to process incoming emails as events without the complexity of a full Mail Transfer Agent (MTA) like Postfix or Exim.Overview of LSMTPD
LSMTPD (Lightweight SMTP Daemon) is a minimal, receive-only SMTP server written in Rust. Its primary purpose is to ingest email via SMTP and forward it directly into an AMQP queue or exchange. Unlike traditional MTAs like Postfix or Exim, it does not support outbound mail, mail storage, or spam filtering, making it more suitable for containerized or microservice environments where the goal is simply to push received mail into a message broker.LSMTPD Repository Layout Overview
LSMTPD uses a modular architecture where each component has a single responsibility to minimize coupling. The project is structured as follows:
src/: Application source codepackages/: Additional packagestarget/: Rust build output (automatically generated by Cargo)
Core Dependency Hierarchy:
main.rscoordinates startup and depends onstate,handler,queue,models, anderrors.LSMTP/ ├── Cargo.toml ├── src/ │ ├── main.rs │ ├── state.rs │ ├── errors.rs │ ├── handler/ (SMTP protocol logic) │ ├── models/ (Data structures) │ └── queue/ (Message delivery) └── target/ (Build artifacts)Message Processing and AMQP Integration
Incoming messages are parsed and queued into an internaltokio::sync::mpscchannel. A dedicated worker task consumes these messages and publishes them to a configured AMQP exchange. This architecture provides backpressure handling to maintain server responsiveness under high load.Understand the LSMTP RabbitMQ email message structure
When building custom workers for LSMTP, messages are retrieved from the RabbitMQ queue as serialized JSON objects. Each message contains metadata about the SMTP transaction and the full email content. Note that email size must comply with your specific RabbitMQ configuration limits.{ "timestamp": "2025-09-23T23:18:51.477629045+00:00", "message_id": "cf4c844f-a317-44f7-97a3-0aaa5be372e3", "client_address": "NEKO-NIK-Example", "recipients": ["<admin@nekonik.com>"], "email_content": "Email body / DATA part", "sender": "from-id@nekonik.org" }Understand LSMTPD Connection Handling
LSMTPD manages incoming SMTP client connections asynchronously usingtokio::spawnto support thousands of concurrent sessions. To prevent idle or stuck connections from consuming resources, the server uses a timeout mechanism controlled by theMAX_TIMEOUT_SECSenvironment variable.Integrate SMTP traffic with AMQP brokers using LSMTPD
LSMTPD provides seamless AMQP integration, allowing emails to flow directly into a message broker. This architecture transforms standard SMTP traffic into events that can be consumed and processed by other systems in a distributed environment.Understand the LSMTPD email processing workflow
LSMTPD processes emails through a sequential lifecycle:
- Client Connection: A client connects via SMTP; LSMTPD spawns an async task using
tokio::spawnwith a 180-second idle timeout. - SMTP Handshake: Client sends
EHLO/HELOand the server responds with itsSERVER_NAME. - Envelope Setup: Client defines the sender via
MAIL FROMand recipients viaRCPT TO. - Message Transfer: Client sends the
DATAcommand and the email body. LSMTPD enforces basic SMTP formatting and size limits (returning error552if exceeded). - Validation: LSMTPD verifies the presence of
MAIL FROM, at least oneRCPT TO, and the message body. - Message Queueing: Valid messages are placed into a
tokio::mpscchannel for a worker task to process. - AMQP Delivery: The worker publishes the email to the configured AMQP exchange using the specified
routing_key. - Connection Close: The session ends via the
QUITcommand or server-side closure.
- Client Connection: A client connects via SMTP; LSMTPD spawns an async task using
Use LSMTPD for event-driven email processing and AMQP integration
LSMTPD is designed for systems where email serves as an input signal or trigger for workflows. Unlike full-featured mail servers, it focuses exclusively on receiving mail and forwarding it directly to an AMQP message broker. This architecture is ideal for:
- Event-Driven Workflows: Automatically creating support tickets, triggering CI/CD jobs, or feeding emails into spam-detection services.
- Cloud-Native Architectures: Due to its minimal footprint, it is suitable for containerized environments (Docker, Kubernetes) and scales horizontally with AMQP infrastructure.
- Bridging Legacy Systems: Connecting older SMTP-based tools to modern event-driven stacks by converting emails into queue messages.
- Workflow Automation: Routing emails (e.g., order confirmations, alerts, form submissions) into queues for processing by billing systems, monitoring dashboards, or CRMs.
- Simple Mail Ingestion: Providing a lightweight alternative to Postfix, Exim, or Sendmail for applications that only need to ingest incoming mail without needing outbound delivery or mailbox management.
Install LSMTPD via the official APT repository
LSMTPD can be installed on Debian-based systems using the official repository hosted at https://apt.nekonik.com. After adding the repository to the system, update the package list and install thelsmtpdpackage. Users may be prompted for initial settings during installation; if no prompts appear, configuration can be handled manually later.sudo apt update sudo apt install lsmtpdVerify hardware and OS requirements for LSMTPD
LSMTPD is a lightweight server with the following environment requirements:
- Operating System: Linux. Debian/Ubuntu are recommended for packaged installations; other distributions are supported via Docker or source builds.
- Architecture: x86_64 (amd64) or ARM64 (via Docker/source build).
- Resources: Minimum 128MB RAM and 1 vCPU.