Logo

Complete Mail Server Installation with Postfix and Dovecot

Complete Mail Server Installation with Postfix and Dovecot

Comprehensive guide to set up a professional email server on Linux

Complete Mail Server Installation with Postfix and Dovecot

Comprehensive guide to set up a professional email server on Linux


Introduction and Architecture

What is a Mail Server?

A mail server handles sending and receiving emails. Our configuration uses two main components:

  • Postfix: Mail Transfer Agent (MTA) - handles SMTP send/receive operations
  • Dovecot: IMAP/POP3 Server - allows clients to access their emails

Global Architecture Diagram

┌─────────────────────────────────────────────────────────────────────────────┐
│                        MAIL SERVER ARCHITECTURE                             │
└─────────────────────────────────────────────────────────────────────────────┘

    INTERNET                        SERVER                          CLIENTS
    ────────                        ──────                          ───────

┌──────────────┐                ┌─────────────────────────────┐
│   External   │    Port 25     │                             │
│   Server     │ ──────────────▶│         POSTFIX             │
│   (SMTP)     │                │      (MTA - SMTP)           │
└──────────────┘                │                             │
                                │   ┌─────────────────────┐   │
                                │   │     Mail Queue      │   │
                                │   │                     │   │
                                │   └─────────────────────┘   │
                                │              │              │
                                │              ▼              │
                                │   ┌─────────────────────┐   │
                                │   │     Maildir         │   │
                                │   │  /var/mail/vhosts/  │   │
                                │   └─────────────────────┘   │
                                │              │              │
                                └──────────────┼──────────────┘
                                               │
                                ┌──────────────┼──────────────┐
                                │              ▼              │
                                │         DOVECOT             │     ┌──────────┐
                                │     (IMAP/POP3 Server)      │────▶│ Outlook  │
                                │                             │     └──────────┘
                                │   Ports: 993 (IMAPS)        │     ┌──────────┐
                                │          995 (POP3S)        │────▶│Thunderbird│
                                │          587 (Submission)   │     └──────────┘
                                └─────────────────────────────┘     ┌──────────┐
                                                                    │ Webmail  │
                                                                    └──────────┘

Communication Flow

┌─────────────────────────────────────────────────────────────────────────────┐
│                         INCOMING EMAIL FLOW                                 │
└─────────────────────────────────────────────────────────────────────────────┘

  ┌─────────┐     ┌─────────┐     ┌─────────┐     ┌─────────┐     ┌─────────┐
  │ External│     │   DNS   │     │ Postfix │     │ Dovecot │     │  Mail   │
  │ Sender  │     │  (MX)   │     │  (MTA)  │     │ (IMAP)  │     │ Client  │
  └────┬────┘     └────┬────┘     └────┬────┘     └────┬────┘     └────┬────┘
       │               │               │               │               │
       │  MX Query     │               │               │               │
       │──────────────▶│               │               │               │
       │               │               │               │               │
       │  MX Response  │               │               │               │
       │◀──────────────│               │               │               │
       │               │               │               │               │
       │          SMTP Connection (port 25)            │               │
       │──────────────────────────────▶│               │               │
       │               │               │               │               │
       │               │               │  Store in     │               │
       │               │               │  Maildir      │               │
       │               │               │──────────────▶│               │
       │               │               │               │               │
       │               │               │               │  IMAP         │
       │               │               │               │  Connection   │
       │               │               │               │  (993)        │
       │               │               │               │◀──────────────│
       │               │               │               │               │
       │               │               │               │  Emails       │
       │               │               │               │──────────────▶│
       │               │               │               │               │
┌─────────────────────────────────────────────────────────────────────────────┐
│                         OUTGOING EMAIL FLOW                                 │
└─────────────────────────────────────────────────────────────────────────────┘

  ┌─────────┐     ┌─────────┐     ┌─────────┐     ┌─────────┐     ┌─────────┐
  │  Mail   │     │ Dovecot │     │ Postfix │     │   DNS   │     │ Remote  │
  │ Client  │     │ (Auth)  │     │  (MTA)  │     │         │     │ Server  │
  └────┬────┘     └────┬────┘     └────┬────┘     └────┬────┘     └────┬────┘
       │               │               │               │               │
       │  SMTP Auth    │               │               │               │
       │  (port 587)   │               │               │               │
       │──────────────▶│               │               │               │
       │               │               │               │               │
       │               │  Validation   │               │               │
       │               │──────────────▶│               │               │
       │               │               │               │               │
       │               │               │  MX Query     │               │
       │               │               │──────────────▶│               │
       │               │               │               │               │
       │               │               │  MX Response  │               │
       │               │               │◀──────────────│               │
       │               │               │               │               │
       │               │               │  Send SMTP    │               │
       │               │               │──────────────────────────────▶│
       │               │               │               │               │

Prerequisites

System Requirements

ElementMinimumRecommended
RAM512 MB2 GB
Storage10 GB50 GB+
OSUbuntu 20.04+ / Debian 11+Ubuntu 22.04 LTS
NetworkStatic public IPDedicated IP

Required Ports

┌─────────────────────────────────────────────────────────────────┐
│                    REQUIRED NETWORK PORTS                       │
├────────┬──────────────┬─────────────────────────────────────────┤
│  Port  │   Protocol   │            Description                  │
├────────┼──────────────┼─────────────────────────────────────────┤
│   25   │   SMTP       │  Receive emails (server to server)      │
│  587   │   Submission │  Send emails (authenticated client)     │
│  465   │   SMTPS      │  SMTP over SSL (legacy)                 │
│  993   │   IMAPS      │  IMAP over SSL (email access)           │
│  995   │   POP3S      │  POP3 over SSL (email download)         │
└────────┴──────────────┴─────────────────────────────────────────┘

Pre-flight Checks

# Check hostname
hostname -f

# Check if port 25 is not blocked
telnet smtp.google.com 25

# Check public IP
curl ifconfig.me

Package Installation

Ubuntu/Debian

# Update system
sudo apt update && sudo apt upgrade -y

# Install Postfix
sudo apt install postfix postfix-policyd-spf-python -y

# During installation, choose:
# - Configuration type: Internet Site
# - Mail name: your-domain.com

# Install Dovecot
sudo apt install dovecot-core dovecot-imapd dovecot-pop3d dovecot-lmtpd -y

# Additional tools
sudo apt install certbot mailutils -y

CentOS/RHEL

# Install EPEL repository
sudo dnf install epel-release -y

# Install Postfix
sudo dnf install postfix -y

# Install Dovecot
sudo dnf install dovecot dovecot-pigeonhole -y

# Enable services
sudo systemctl enable postfix dovecot

DNS Configuration

Required DNS Records

┌─────────────────────────────────────────────────────────────────────────────┐
│                    REQUIRED DNS CONFIGURATION                               │
└─────────────────────────────────────────────────────────────────────────────┘

┌─────────────────────────────────────────────────────────────────────────────┐
│  TYPE  │        NAME        │           VALUE                 │    TTL     │
├────────┼────────────────────┼─────────────────────────────────┼────────────┤
│   A    │  mail              │  203.0.113.10                   │    3600    │
│   MX   │  @                 │  10 mail.your-domain.com        │    3600    │
│  TXT   │  @                 │  v=spf1 mx a -all               │    3600    │
│  TXT   │  _dmarc            │  v=DMARC1; p=quarantine         │    3600    │
│  PTR   │  10.113.0.203      │  mail.your-domain.com           │    3600    │
└────────┴────────────────────┴─────────────────────────────────┴────────────┘

Legend:
  • A    : Points "mail" subdomain to server IP
  • MX   : Indicates mail server for the domain
  • TXT  : SPF for outgoing email authentication
  • TXT  : DMARC for email handling policy
  • PTR  : Reverse DNS (configure with hosting provider)

DNS Verification

# Check MX record
dig MX your-domain.com +short

# Check A record
dig A mail.your-domain.com +short

# Check SPF
dig TXT your-domain.com +short

# Check reverse DNS
dig -x YOUR_PUBLIC_IP +short

Postfix Configuration

Postfix Internal Architecture

┌─────────────────────────────────────────────────────────────────────────────┐
│                    POSTFIX INTERNAL ARCHITECTURE                            │
└─────────────────────────────────────────────────────────────────────────────┘

                              ┌──────────────────┐
                              │    smtpd         │◀─── Port 25 (incoming)
                              │  (reception)     │◀─── Port 587 (submission)
                              └────────┬─────────┘
                                       │
                                       ▼
                              ┌──────────────────┐
                              │    cleanup       │
                              │  (verification)  │
                              └────────┬─────────┘
                                       │
                                       ▼
                              ┌──────────────────┐
                              │     qmgr         │
                              │ (queue manager)  │
                              │                  │
                              └────────┬─────────┘
                                       │
              ┌────────────────────────┼────────────────────────┐
              │                        │                        │
              ▼                        ▼                        ▼
     ┌──────────────┐         ┌──────────────┐         ┌──────────────┐
     │    smtp      │         │    lmtp      │         │   local      │
     │  (outgoing)  │         │  (Dovecot)   │         │  (system)    │
     └──────────────┘         └──────────────┘         └──────────────┘
              │                        │                        │
              ▼                        ▼                        ▼
     External servers          Dovecot LMTP              /var/mail/

File /etc/postfix/main.cf

# Create backup
sudo cp /etc/postfix/main.cf /etc/postfix/main.cf.backup

# Edit main configuration file
sudo nano /etc/postfix/main.cf
# =============================================================================
# POSTFIX - MAIN CONFIGURATION
# =============================================================================

# -----------------------------------------------------------------------------
# SERVER IDENTITY
# -----------------------------------------------------------------------------
myhostname = mail.your-domain.com
mydomain = your-domain.com
myorigin = $mydomain

# -----------------------------------------------------------------------------
# NETWORKS AND INTERFACES
# -----------------------------------------------------------------------------
inet_interfaces = all
inet_protocols = ipv4
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128

# -----------------------------------------------------------------------------
# MAILBOXES
# -----------------------------------------------------------------------------
home_mailbox = Maildir/
mailbox_size_limit = 0
recipient_delimiter = +

# -----------------------------------------------------------------------------
# TLS/SSL
# -----------------------------------------------------------------------------
smtpd_tls_cert_file = /etc/letsencrypt/live/mail.your-domain.com/fullchain.pem
smtpd_tls_key_file = /etc/letsencrypt/live/mail.your-domain.com/privkey.pem
smtpd_tls_security_level = may
smtpd_tls_auth_only = yes
smtpd_tls_loglevel = 1
smtpd_tls_received_header = yes
smtpd_tls_session_cache_timeout = 3600s

smtp_tls_security_level = may
smtp_tls_loglevel = 1

# Secure protocols and ciphers
smtpd_tls_mandatory_protocols = !SSLv2, !SSLv3, !TLSv1, !TLSv1.1
smtpd_tls_protocols = !SSLv2, !SSLv3, !TLSv1, !TLSv1.1
smtp_tls_mandatory_protocols = !SSLv2, !SSLv3, !TLSv1, !TLSv1.1
smtp_tls_protocols = !SSLv2, !SSLv3, !TLSv1, !TLSv1.1

# -----------------------------------------------------------------------------
# SASL AUTHENTICATION (via Dovecot)
# -----------------------------------------------------------------------------
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
smtpd_sasl_local_domain = $myhostname
broken_sasl_auth_clients = yes

# -----------------------------------------------------------------------------
# RESTRICTIONS
# -----------------------------------------------------------------------------
smtpd_helo_required = yes
smtpd_helo_restrictions =
    permit_mynetworks,
    permit_sasl_authenticated,
    reject_invalid_helo_hostname,
    reject_non_fqdn_helo_hostname

smtpd_sender_restrictions =
    permit_mynetworks,
    permit_sasl_authenticated,
    reject_non_fqdn_sender,
    reject_unknown_sender_domain

smtpd_recipient_restrictions =
    permit_mynetworks,
    permit_sasl_authenticated,
    reject_unauth_destination,
    reject_non_fqdn_recipient,
    reject_unknown_recipient_domain

# -----------------------------------------------------------------------------
# LIMITS AND PERFORMANCE
# -----------------------------------------------------------------------------
message_size_limit = 52428800
mailbox_size_limit = 0
smtpd_client_connection_count_limit = 10
smtpd_client_connection_rate_limit = 30

File /etc/postfix/master.cf

sudo nano /etc/postfix/master.cf
# =============================================================================
# POSTFIX - SERVICES
# =============================================================================

# Standard SMTP service (port 25)
smtp      inet  n       -       y       -       -       smtpd

# Submission (port 587) - for authenticated clients
submission inet n       -       y       -       -       smtpd
  -o syslog_name=postfix/submission
  -o smtpd_tls_security_level=encrypt
  -o smtpd_sasl_auth_enable=yes
  -o smtpd_tls_auth_only=yes
  -o smtpd_reject_unlisted_recipient=no
  -o smtpd_recipient_restrictions=permit_sasl_authenticated,reject
  -o milter_macro_daemon_name=ORIGINATING

# SMTPS (port 465) - SMTP over SSL
smtps     inet  n       -       y       -       -       smtpd
  -o syslog_name=postfix/smtps
  -o smtpd_tls_wrappermode=yes
  -o smtpd_sasl_auth_enable=yes
  -o smtpd_reject_unlisted_recipient=no
  -o smtpd_recipient_restrictions=permit_sasl_authenticated,reject
  -o milter_macro_daemon_name=ORIGINATING

Dovecot Configuration

Dovecot Internal Architecture

┌─────────────────────────────────────────────────────────────────────────────┐
│                    DOVECOT INTERNAL ARCHITECTURE                            │
└─────────────────────────────────────────────────────────────────────────────┘

   Mail Clients                    Dovecot                       Storage
   ────────────                    ───────                       ───────

┌────────────┐
│  Outlook   │──┐
└────────────┘  │         ┌─────────────────────────────┐
                │         │                             │
┌────────────┐  │  IMAPS  │   ┌─────────────────────┐   │
│Thunderbird │──┼────────▶│   │    imap-login       │   │
└────────────┘  │  (993)  │   │    (authentication) │   │
                │         │   └──────────┬──────────┘   │
┌────────────┐  │         │              │              │
│   Mobile   │──┘         │              ▼              │
└────────────┘            │   ┌─────────────────────┐   │     ┌───────────────┐
                          │   │    imap             │   │     │               │
                          │   │    (protocol)       │   │────▶│   Maildir     │
                          │   └─────────────────────┘   │     │               │
                          │                             │     │ /var/mail/    │
                          │   ┌─────────────────────┐   │     │   vhosts/     │
                          │   │    auth             │───┼────▶│   domain/     │
                          │   │    (SASL)           │   │     │     user/     │
                          │   └──────────┬──────────┘   │     │               │
                          │              │              │     └───────────────┘
                          │              ▼              │
                          │   ┌─────────────────────┐   │
       Postfix ◀──────────│   │    auth-userdb      │   │
       (SASL)             │   │    (socket)         │   │
                          │   └─────────────────────┘   │
                          │                             │
                          └─────────────────────────────┘

File /etc/dovecot/dovecot.conf

sudo nano /etc/dovecot/dovecot.conf
# =============================================================================
# DOVECOT - MAIN CONFIGURATION
# =============================================================================

# Enabled protocols
protocols = imap pop3 lmtp

# Listen on all interfaces
listen = *, ::

# Include modular configurations
!include conf.d/*.conf

File /etc/dovecot/conf.d/10-mail.conf

sudo nano /etc/dovecot/conf.d/10-mail.conf
# =============================================================================
# DOVECOT - MAIL STORAGE CONFIGURATION
# =============================================================================

# Mailbox location (Maildir format)
mail_location = maildir:~/Maildir

# Namespace for inbox
namespace inbox {
  inbox = yes
}

# User/group for mail access
mail_uid = vmail
mail_gid = vmail

# Privileges
mail_privileged_group = mail

# First valid UID/GID
first_valid_uid = 1000
first_valid_gid = 1000

File /etc/dovecot/conf.d/10-auth.conf

sudo nano /etc/dovecot/conf.d/10-auth.conf
# =============================================================================
# DOVECOT - AUTHENTICATION
# =============================================================================

# Disable plaintext auth without SSL
disable_plaintext_auth = yes

# Authentication mechanisms
auth_mechanisms = plain login

# Include system configuration
!include auth-system.conf.ext

File /etc/dovecot/conf.d/10-ssl.conf

sudo nano /etc/dovecot/conf.d/10-ssl.conf
# =============================================================================
# DOVECOT - SSL/TLS CONFIGURATION
# =============================================================================

# Enable SSL
ssl = required

# Let's Encrypt certificates
ssl_cert = </etc/letsencrypt/live/mail.your-domain.com/fullchain.pem
ssl_key = </etc/letsencrypt/live/mail.your-domain.com/privkey.pem

# Allowed protocols (disable legacy)
ssl_min_protocol = TLSv1.2

# Prefer server ciphers
ssl_prefer_server_ciphers = yes

# Secure ciphers
ssl_cipher_list = ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384

File /etc/dovecot/conf.d/10-master.conf

sudo nano /etc/dovecot/conf.d/10-master.conf
# =============================================================================
# DOVECOT - SERVICES AND SOCKETS
# =============================================================================

service imap-login {
  inet_listener imap {
    port = 0  # Disabled (insecure)
  }
  inet_listener imaps {
    port = 993
    ssl = yes
  }
}

service pop3-login {
  inet_listener pop3 {
    port = 0  # Disabled (insecure)
  }
  inet_listener pop3s {
    port = 995
    ssl = yes
  }
}

service lmtp {
  unix_listener /var/spool/postfix/private/dovecot-lmtp {
    mode = 0600
    user = postfix
    group = postfix
  }
}

# Authentication socket for Postfix
service auth {
  unix_listener /var/spool/postfix/private/auth {
    mode = 0666
    user = postfix
    group = postfix
  }
  
  unix_listener auth-userdb {
    mode = 0600
    user = vmail
  }
  
  user = dovecot
}

service auth-worker {
  user = vmail
}

SSL/TLS Security

Obtain Let's Encrypt Certificate

# Temporarily stop services
sudo systemctl stop postfix dovecot

# Obtain certificate
sudo certbot certonly --standalone -d mail.your-domain.com

# Restart services
sudo systemctl start postfix dovecot

Automatic Renewal

# Create renewal script
sudo nano /etc/letsencrypt/renewal-hooks/post/mail-services.sh
#!/bin/bash
systemctl reload postfix
systemctl reload dovecot
# Make executable
sudo chmod +x /etc/letsencrypt/renewal-hooks/post/mail-services.sh

# Test renewal
sudo certbot renew --dry-run

SASL Authentication

Authentication Flow Diagram

┌─────────────────────────────────────────────────────────────────────────────┐
│                    SASL AUTHENTICATION FLOW                                 │
└─────────────────────────────────────────────────────────────────────────────┘

  ┌─────────┐     ┌─────────┐     ┌─────────┐     ┌─────────┐     ┌─────────┐
  │  Mail   │     │ Postfix │     │  Auth   │     │ Dovecot │     │  PAM/   │
  │ Client  │     │  SMTP   │     │ Socket  │     │  Auth   │     │ Passwd  │
  └────┬────┘     └────┬────┘     └────┬────┘     └────┬────┘     └────┬────┘
       │               │               │               │               │
       │  EHLO         │               │               │               │
       │──────────────▶│               │               │               │
       │               │               │               │               │
       │  250-AUTH     │               │               │               │
       │◀──────────────│               │               │               │
       │               │               │               │               │
       │  AUTH LOGIN   │               │               │               │
       │  user:pass    │               │               │               │
       │──────────────▶│               │               │               │
       │               │               │               │               │
       │               │  Verify       │               │               │
       │               │──────────────▶│               │               │
       │               │               │               │               │
       │               │               │  Check        │               │
       │               │               │──────────────▶│               │
       │               │               │               │               │
       │               │               │               │  Validate    │
       │               │               │               │──────────────▶│
       │               │               │               │               │
       │               │               │               │  OK/FAIL     │
       │               │               │               │◀─────────────│
       │               │               │               │               │
       │               │               │  Result       │               │
       │               │               │◀─────────────│               │
       │               │               │               │               │
       │               │  Result       │               │               │
       │               │◀─────────────│               │               │
       │               │               │               │               │
       │  235 Auth OK  │               │               │               │
       │◀──────────────│               │               │               │
       │               │               │               │               │

Create Mail User

# Create vmail group
sudo groupadd -g 5000 vmail

# Create vmail user
sudo useradd -g vmail -u 5000 vmail -d /var/mail

# Create storage directory
sudo mkdir -p /var/mail/vhosts/your-domain.com

# Set permissions
sudo chown -R vmail:vmail /var/mail/vhosts

# Create system user for mail
sudo useradd -m -s /bin/bash user1
sudo passwd user1

# Create Maildir structure
sudo -u user1 mkdir -p /home/user1/Maildir/{cur,new,tmp}

Testing and Validation

Complete Test Script

#!/bin/bash
# test-mail-server.sh

echo "=== Mail Server Test ==="

# Test 1: Check Postfix is listening
echo -n "Port 25 (SMTP): "
nc -zv localhost 25 2>&1 | grep -q "succeeded" && echo "OK" || echo "ERROR"

echo -n "Port 587 (Submission): "
nc -zv localhost 587 2>&1 | grep -q "succeeded" && echo "OK" || echo "ERROR"

# Test 2: Check Dovecot is listening
echo -n "Port 993 (IMAPS): "
nc -zv localhost 993 2>&1 | grep -q "succeeded" && echo "OK" || echo "ERROR"

echo -n "Port 995 (POP3S): "
nc -zv localhost 995 2>&1 | grep -q "succeeded" && echo "OK" || echo "ERROR"

# Test 3: Check SSL certificate
echo -n "SSL Certificate: "
openssl s_client -connect localhost:993 -servername mail.your-domain.com </dev/null 2>/dev/null | grep -q "Verify return code: 0" && echo "OK" || echo "CHECK"

# Test 4: Check Postfix configuration
echo -n "Postfix Configuration: "
postfix check 2>&1 | grep -q "error" && echo "ERROR" || echo "OK"

# Test 5: Check Dovecot configuration
echo -n "Dovecot Configuration: "
dovecot -n 2>&1 | grep -q "Error" && echo "ERROR" || echo "OK"

echo "=== Tests Complete ==="

Send Test Email

# Via command line
echo "This is a test" | mail -s "Test Email" [email protected]

# Check logs
sudo tail -f /var/log/mail.log

Test with Telnet/OpenSSL

# SMTP test
openssl s_client -connect mail.your-domain.com:587 -starttls smtp

# IMAP test
openssl s_client -connect mail.your-domain.com:993

Troubleshooting

Diagnostic Commands

# Check service status
sudo systemctl status postfix
sudo systemctl status dovecot

# Watch logs in real-time
sudo tail -f /var/log/mail.log
sudo tail -f /var/log/mail.err

# Check Postfix queue
sudo postqueue -p

# Force queue delivery
sudo postqueue -f

# Delete all queued messages
sudo postsuper -d ALL

# Test Postfix configuration
sudo postfix check

# Test Dovecot configuration
sudo doveconf -n

Common Issues

ProblemProbable CauseSolution
Connection refused port 25Postfix not running or port blockedsystemctl start postfix / Check firewall
SSL handshake failedInvalid or expired certificateRenew with certbot renew
Authentication failedWrong password or SASL configCheck /var/log/auth.log
Emails rejectedSPF/DKIM/DMARC misconfiguredVerify DNS records
Maildir not createdIncorrect permissionschown -R vmail:vmail /var/mail

Decision Tree

┌─────────────────────────────────────────────────────────────────────────────┐
│                    TROUBLESHOOTING DECISION TREE                            │
└─────────────────────────────────────────────────────────────────────────────┘

                           ┌─────────────────┐
                           │ Email not       │
                           │ sending?        │
                           └────────┬────────┘
                                    │
                    ┌───────────────┴───────────────┐
                    ▼                               ▼
           ┌───────────────┐               ┌───────────────┐
           │ Service       │               │ Service       │
           │ running?      │               │ stopped       │
           └───────┬───────┘               └───────┬───────┘
                   │                               │
                   ▼                               ▼
        ┌──────────────────┐            ┌──────────────────┐
        │ Check mail.log   │            │ systemctl start  │
        │ for errors       │            │ postfix          │
        └────────┬─────────┘            └──────────────────┘
                 │
    ┌────────────┼────────────┐
    ▼            ▼            ▼
┌────────┐  ┌────────┐  ┌────────┐
│ Auth   │  │ DNS    │  │ Quota  │
│ Error  │  │ Error  │  │ Error  │
└───┬────┘  └───┬────┘  └───┬────┘
    │           │           │
    ▼           ▼           ▼
┌────────┐  ┌────────┐  ┌────────┐
│Check   │  │Check   │  │Check   │
│password│  │MX, SPF │  │disk    │
│& SASL  │  │DMARC   │  │space   │
└────────┘  └────────┘  └────────┘

File Summary

┌─────────────────────────────────────────────────────────────────────────────┐
│                    CONFIGURATION FILE STRUCTURE                             │
└─────────────────────────────────────────────────────────────────────────────┘

/etc/
├── postfix/
│   ├── main.cf              ← Main Postfix configuration
│   ├── master.cf            ← Services and ports
│   └── main.cf.backup       ← Backup
│
├── dovecot/
│   ├── dovecot.conf         ← Main Dovecot configuration
│   └── conf.d/
│       ├── 10-mail.conf     ← Mail storage
│       ├── 10-auth.conf     ← Authentication
│       ├── 10-ssl.conf      ← SSL certificates
│       └── 10-master.conf   ← Services and sockets
│
└── letsencrypt/
    └── live/
        └── mail.your-domain.com/
            ├── fullchain.pem    ← Certificate + chain
            └── privkey.pem      ← Private key

/var/
├── mail/
│   └── vhosts/
│       └── your-domain.com/     ← Mailboxes (Maildir)
│
└── log/
    ├── mail.log             ← Main logs
    └── mail.err             ← Errors

Appendices

A. Useful Commands

# Service management
sudo systemctl {start|stop|restart|status} postfix
sudo systemctl {start|stop|restart|status} dovecot

# Logs
sudo journalctl -u postfix -f
sudo journalctl -u dovecot -f

# Queue
sudo postqueue -p          # Show queue
sudo postsuper -d ALL      # Clear queue

# Users
sudo doveadm user '*'      # List users

B. Deployment Checklist

  • DNS: A, MX, SPF, DMARC records configured
  • Reverse DNS (PTR) configured
  • SSL certificate obtained and valid
  • Postfix configured and tested
  • Dovecot configured and tested
  • SASL authentication working
  • Firewall: Ports 25, 587, 993, 995 open
  • Send and receive test successful
  • Automatic certificate renewal configured

Join our Discord community server

For any questions, suggestions, or just to chat with the community, join us on Discord!

900+Members