For many small to medium businesses and technical teams, the mail system is one of the most critical — yet often overlooked — internal services.
Building your own secure, reliable, and maintainable mail infrastructure can greatly reduce long-term service costs while giving you full control over your organization’s data and privacy.
In this article, I’ll introduce the complete mail server architecture I’m currently running, along with the role of each component and the user scenarios they support.
🧩 System Overview
[Internet]
│
▼
┌────────────┐
│ Postfix │ ← SMTP send/receive, DKIM signing, initial spam filtering
└────────────┘
│
▼
┌────────────┐
│ Amavis │ ← Central filter layer, connects ClamAV & SpamAssassin
└────────────┘
│
▼
┌────────────┐
│ Dovecot │ ← IMAP/POP3 access, mailbox storage, Sieve rules
└────────────┘
│
▼
┌────────────┐
│ Piler │ ← Mail archiving and search
└────────────┘
Supporting components:
- PostfixAdmin → Manage domains, virtual users, and self-service password changes
- MariaDB → Store user, domain, and relay configuration data
- Roundcube → Webmail interface
- ClamAV → Virus scanning
- SpamAssassin → Anti-spam filtering and learning
- Amavis → Integrates ClamAV, SpamAssassin, DKIM, SPF, and DMARC checks
- Piler → Mail archiving and full-text search for long-term storage
🔧 Role of Each Component
🏣 Postfix — The Core SMTP Engine
Postfix is the heart of the system, responsible for sending and receiving email via SMTP.
It accepts inbound mail based on your DNS MX record and delivers messages internally to Dovecot for local storage.
Outgoing messages are also handled through Postfix (relay).
Typical scenarios:
- Users send mail via Outlook, Thunderbird, or mobile clients through SMTP authentication.
- Incoming messages from external servers are first processed by Postfix before passing through Amavis for filtering.
👩💻 PostfixAdmin — Domain & User Management
A lightweight PHP web interface that allows administrators (and users) to manage:
- Mail domains
- Virtual users and aliases
- Password changes
- Forwarding addresses
Use cases:
- Create a new department domain such as
marketing.company.com - Users reset their own passwords
- Admins define alias or group mailboxes
🗃️ MariaDB — Configuration & User Database
MariaDB stores key configuration data for Postfix and Dovecot, including:
- Domain lists
- User accounts and hashed passwords
- Aliases and forwarding rules
- Mailbox quotas
📬 Dovecot — IMAP/POP3 and Mailbox Management
Dovecot provides IMAP/POP3 access for users via desktop or mobile clients.
It also supports:
- Sieve filters for automatic sorting or forwarding
- Spam/ham training
- Quota enforcement
Example:
- A manager’s inbox is automatically sorted into folders using Sieve rules
- Users mark spam to help improve the system’s learning model
🧱 Amavis — The Content Filtering Hub
Amavis is the central filtering engine. Every incoming message passes through it for content inspection.
It invokes:
- ClamAV for virus scanning
- SpamAssassin for spam scoring
- DKIM, SPF, and DMARC validation
Purpose:
- Block infected attachments
- Tag or quarantine spam
- Ensure sender authenticity through DKIM signing
🦠 ClamAV — Virus Protection
ClamAV is an open-source antivirus engine that scans every message attachment for malware.
Use case: Prevent ransomware or malicious executables from entering your system.
🚫 SpamAssassin — Anti-Spam Filtering
SpamAssassin analyzes message headers, content, blacklists, and language patterns to assign a spam score.
Messages exceeding a defined threshold are marked or moved to the Junk folder.
It also supports continual learning through user feedback.
🌐 Roundcube — Webmail Interface
Roundcube provides a user-friendly webmail interface that supports:
- Full mail management (send/receive/search)
- HTML editing and attachments
- Folder organization
- Sieve rule management
Ideal for remote users or employees without local mail clients.
📦 Piler — Mail Archiving & Search
Piler is an enterprise-grade archiving system that securely stores all incoming and outgoing mail.
It indexes subjects, senders, and even attachment text for fast searching.
Benefits:
- Compliance-ready long-term storage
- Legal discovery and audit support
- Prevent data loss from accidental deletions
💡 User Scenarios
| User Role | Requirement | System Components |
|---|---|---|
| Regular Employee | Send/receive mail via Outlook | Postfix + Dovecot |
| New Employee | Create account and set password | PostfixAdmin + MariaDB |
| Sales Staff | Access mail from mobile or browser | Roundcube + Dovecot |
| IT Admin | Monitor spam and virus activity | Amavis + SpamAssassin + ClamAV |
| Auditor / Legal | Search archived messages | Piler |
| Management | Create group mailboxes or forwarding rules | PostfixAdmin |
🔄 How It All Works
- Incoming mail arrives via Postfix
- Postfix hands the message to Amavis
- Amavis runs scans using ClamAV and SpamAssassin
- If the message passes checks, it’s delivered to Dovecot
- A copy is sent to Piler for archiving
- Users access their mail via Roundcube or mail clients
🏁 Conclusion
Although this mail system combines several open-source components, when properly configured it delivers enterprise-level performance, stability, and security.
In the upcoming articles, I’ll dive deeper into each module — starting with Postfix — and walk through how to build your own professional mail environment step by step.