Postfix is the most common Mail Transfer Agent (MTA) on Linux, responsible for routing and delivering email.
Installation
# Debian / Ubuntu
sudo apt install postfix
# RHEL / CentOS / Fedora
sudo dnf install postfix
# Arch Linux
sudo pacman -S postfixDuring installation on Debian/Ubuntu, select "Internet Site" when prompted for the mail server configuration type.
Service Management
sudo systemctl enable --now postfix # Start and enable on boot
sudo systemctl restart postfix # Restart after major config changes
sudo systemctl reload postfix # Reload config without restarting
sudo systemctl status postfix # Check service statusConfiguration (/etc/postfix/main.cf)
Key directives in the main configuration file:
# Hostname and domain
myhostname = mail.example.com
mydomain = example.com
myorigin = $mydomain
# Network interfaces to listen on
inet_interfaces = all # Listen on all interfaces
inet_protocols = ipv4 # Use IPv4 only (or "all" for dual-stack)
# Trusted networks (allowed to relay mail through this server)
mynetworks = 127.0.0.0/8 192.168.1.0/24
# Destination domains this server accepts mail for
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
# Mailbox location
home_mailbox = Maildir/ # Deliver to ~/Maildir/ (Maildir format)
# Relay host (route all outgoing mail through another SMTP server)
# relayhost = [smtp.relay.com]:587After editing, always reload:
sudo postfix check # Check config for errors
sudo systemctl reload postfixChecking the Mail Queue
mailq # List all emails currently in the queue
postqueue -p # Same as mailq (Postfix native)
postqueue -j # Show queue in JSON formatManaging the Mail Queue
# Force delivery of all queued emails
postqueue -f
# Force delivery for a specific domain
postqueue -s example.com
# Delete a specific email by Queue ID (get ID from mailq)
sudo postsuper -d <Queue-ID>
# Delete ALL emails from the queue (use with extreme caution)
sudo postsuper -d ALL
# Delete all messages in the "deferred" queue only
sudo postsuper -d ALL deferred
# Put a message on hold (prevents delivery attempts)
sudo postsuper -h <Queue-ID>
# Release a held message
sudo postsuper -H <Queue-ID>Viewing Mail Details
# View the content (headers and body) of a queued email
sudo postcat -q <Queue-ID>Troubleshooting (Logs)
Mail logs are the primary tool for diagnosing delivery problems.
# Debian / Ubuntu
tail -f /var/log/mail.log
# RHEL / CentOS
tail -f /var/log/maillog
# Using journalctl
journalctl -u postfix -fCommon Log Status Terms
status=sent— Successfully delivered.status=deferred— Temporary failure (e.g., greylisting, network error). Postfix will retry.status=bounced— Permanent failure (e.g., invalid address, rejected by recipient server).
Useful Postfix Commands
# Show all current Postfix configuration (defaults + overrides)
postconf
# Show only non-default configuration values
postconf -n
# Show a specific parameter
postconf myhostname
# Set a parameter via command line (edits main.cf)
sudo postconf -e "relayhost = [smtp.relay.com]:587"