Quick Reference

Cheatsheets

Practical command references for Linux, networking, servers, containers, databases, and more.

Cheatsheet#mail-ops-cheatsheet

Mail Operations (Postfix) Cheatsheet

Managing a mail server usually involves interacting with Postfix, the most common Mail Transfer Agent (MTA) on Linux.

Checking the Mail Queue

mailq                      # List all emails currently in the queue
postqueue -p               # Same as mailq
postqueue -j               # Show queue in JSON format

Managing 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 from the queue (requires Queue 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
sudo postsuper -d ALL deferred

Viewing Mail Details

# View the content (headers and body) of a queued email
sudo postcat -q <Queue-ID>

Troubleshooting Delivery (Logs)

Mail logs are the best place to find out why an email bounced or was deferred.

# Debian / Ubuntu
tail -f /var/log/mail.log
 
# RHEL / CentOS
tail -f /var/log/maillog

Common Log Terms

  • status=sent: Successfully delivered.
  • status=deferred: Delivery failed temporarily (e.g., greylisting, temporary network error). Postfix will retry later.
  • status=bounced: Delivery failed permanently (e.g., invalid address, blocked by spam filter).

Basic Postfix Configuration

The main configuration file is usually located at /etc/postfix/main.cf. After editing this file, always reload Postfix:

sudo systemctl reload postfix