Skip to content

Nuface Blog

隨意隨手記 Casual Notes

Menu
  • Home
  • About
  • Services
  • Blog
  • Contact
  • Privacy Policy
  • Login
Menu

Building an Enterprise-Grade Mail Server: Full Architecture Overview

Posted on 2025-11-072025-11-07 by Rico

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 RoleRequirementSystem Components
Regular EmployeeSend/receive mail via OutlookPostfix + Dovecot
New EmployeeCreate account and set passwordPostfixAdmin + MariaDB
Sales StaffAccess mail from mobile or browserRoundcube + Dovecot
IT AdminMonitor spam and virus activityAmavis + SpamAssassin + ClamAV
Auditor / LegalSearch archived messagesPiler
ManagementCreate group mailboxes or forwarding rulesPostfixAdmin

🔄 How It All Works

  1. Incoming mail arrives via Postfix
  2. Postfix hands the message to Amavis
  3. Amavis runs scans using ClamAV and SpamAssassin
  4. If the message passes checks, it’s delivered to Dovecot
  5. A copy is sent to Piler for archiving
  6. 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.

Recent Posts

  • Postfix + Let’s Encrypt + BIND9 + DANE Fully Automated TLSA Update Guide
  • Postfix + Let’s Encrypt + BIND9 + DANE TLSA 指紋自動更新完整教學
  • Deploying DANE in Postfix
  • 如何在 Postfix 中部署 DANE
  • DANE: DNSSEC-Based TLS Protection

Recent Comments

  1. Building a Complete Enterprise-Grade Mail System (Overview) - Nuface Blog on High Availability Architecture, Failover, GeoDNS, Monitoring, and Email Abuse Automation (SOAR)
  2. Building a Complete Enterprise-Grade Mail System (Overview) - Nuface Blog on MariaDB + PostfixAdmin: The Core of Virtual Domain & Mailbox Management
  3. Building a Complete Enterprise-Grade Mail System (Overview) - Nuface Blog on Daily Operations, Monitoring, and Performance Tuning for an Enterprise Mail System
  4. Building a Complete Enterprise-Grade Mail System (Overview) - Nuface Blog on Final Chapter: Complete Troubleshooting Guide & Frequently Asked Questions (FAQ)
  5. Building a Complete Enterprise-Grade Mail System (Overview) - Nuface Blog on Network Architecture, DNS Configuration, TLS Design, and Postfix/Dovecot SNI Explained

Archives

  • December 2025
  • November 2025
  • October 2025

Categories

  • AI
  • Apache
  • Cybersecurity
  • Database
  • DNS
  • Docker
  • Fail2Ban
  • FileSystem
  • Firewall
  • Linux
  • LLM
  • Mail
  • N8N
  • OpenLdap
  • OPNsense
  • PHP
  • QoS
  • Samba
  • Switch
  • Virtualization
  • VPN
  • WordPress
© 2025 Nuface Blog | Powered by Superbs Personal Blog theme