Postfix and Dovecot Cheat Sheet for RHEL, AlmaLinux and Rocky Linux

A one-page reference for the Postfix and Dovecot commands you actually use when running mail on Red Hat Enterprise Linux, AlmaLinux, Rocky Linux, Oracle Linux and CentOS Stream. Everything here works with the AppStream packages on EL9 (Postfix 3.5, Dovecot 2.3.16) and EL10 (Postfix 3.8, Dovecot 2.3.21). For a full server build, see Configure Postfix and Dovecot on RHEL, AlmaLinux, Rocky and Oracle Linux.

Most commands need root. Replace QUEUE_ID, alice and example.com with your own values.

Install and service control

CommandWhat it does
dnf install postfix dovecotInstall from AppStream (add postfix-lmdb on EL9)
dnf install postfix-perl-scriptsAdds qshape and pflogsumm
systemctl enable --now postfix dovecotStart now and at boot
systemctl reload postfixRe-read main.cf/master.cf without dropping connections
postfix checkCheck configuration and file permissions
postfix statusShow whether the Postfix master is running
postfix flushAttempt delivery of all deferred mail now
alternatives --display mtaConfirm Postfix owns /usr/sbin/sendmail

postconf: read and change configuration

CommandWhat it does
postconf -nShow only settings changed from defaults (start here)
postconf myhostnameShow the current value of one parameter
postconf -d myhostnameShow the built-in default for a parameter
postconf -e 'relayhost = [smtp.example.com]:587'Set a parameter in main.cf
postconf -X relayhostRemove a parameter from main.cf (back to default)
postconf -MList services defined in master.cf
postconf -PList per-service -o overrides in master.cf
postconf -mList supported lookup table types (lmdb, cdb, hash…)
postconf -aList SASL server plugins (should include dovecot)
postconf mail_versionShow the running Postfix version

Mail queue

CommandWhat it does
postqueue -pList the queue (same as mailq)
postqueue -p | tail -n 1One-line summary: total size and number of requests
postqueue -jQueue listing as JSON, one message per line
postqueue -fFlush: retry all deferred mail
postqueue -i QUEUE_IDRetry one message now
postcat -q QUEUE_IDShow a queued message (envelope, headers, body)
postcat -hq QUEUE_IDShow only the headers of a queued message
postsuper -d QUEUE_IDDelete one message
postsuper -d ALL deferredDelete every deferred message
postsuper -d ALLDelete the entire queue (careful)
postsuper -h QUEUE_IDPut a message on hold
postsuper -H QUEUE_IDRelease a held message
postsuper -r ALLRequeue everything (after fixing transport or relay settings)
qshape deferredDeferred mail grouped by destination domain and age

Delete all queued mail from one sender (useful after a compromised account):

postqueue -j | jq -r 'select(.sender=="spammer@example.com") | .queue_id' | postsuper -d -

Lookup tables and aliases

EL10 has no Berkeley DB, so hash: tables fail. Use lmdb: on both EL9 and EL10.

CommandWhat it does
postmap lmdb:/etc/postfix/virtualRebuild a table after editing the source file
postmap -q info@example.com lmdb:/etc/postfix/virtualLook up one key in a table
postmap -q alice@example.com ldap:/etc/postfix/ldap-aliases.cfTest an LDAP lookup table
newaliasesRebuild /etc/aliases (same as postalias on alias_database)
postalias -q root lmdb:/etc/aliasesShow where an alias expands to
postconf -n | grep -E 'hash:|btree:'Find Berkeley DB tables to convert before an EL10 upgrade
postconf -e 'default_database_type = lmdb'Make lmdb the default map type

Logs and tracing

CommandWhat it does
tail -f /var/log/maillogFollow Postfix and Dovecot logs (rsyslog)
journalctl -u postfix -u dovecot -fSame from the journal, for hosts without rsyslog
grep QUEUE_ID /var/log/maillogFollow one message through every Postfix process
grep 'status=deferred' /var/log/maillog | tailRecent deliveries that failed temporarily
grep -E 'reject|warning|fatal' /var/log/maillogRejections and errors
pflogsumm /var/log/maillogDaily traffic summary report
postconf -e 'smtp_tls_loglevel = 1'Log outbound TLS negotiation details
postconf -e 'debug_peer_list = 192.0.2.10'Verbose logging for one problem client only

Testing SMTP, submission and TLS

CommandWhat it does
echo body | mail -s test alice@example.comLocal test message (s-nail package)
sendmail -bv alice@example.comAsk Postfix how it would deliver an address (report is mailed back)
openssl s_client -connect mail.example.com:25 -starttls smtpSTARTTLS on port 25: check certificate and chain
openssl s_client -connect mail.example.com:587 -starttls smtpSTARTTLS on submission port 587
openssl s_client -connect mail.example.com:993IMAPS certificate check
swaks --server mail.example.com:587 --tls --auth LOGIN --auth-user alice --to you@gmail.comAuthenticated send test (swaks from EPEL)
swaks --server mail.example.com:25 --to someone@gmail.comOpen relay test from outside: must be rejected
dig +short MX example.comCheck MX record
dig +short -x 203.0.113.25Check reverse DNS (PTR) for the mail server IP
dig +short TXT example.comCheck SPF (and other TXT) records

Dovecot: configuration and authentication

CommandWhat it does
doveconf -nShow non-default Dovecot settings (and catch syntax errors)
doveconf -a | grep -E "^protocols"Show enabled protocols
doveconf mail_locationShow one setting
doveadm reloadReload configuration
doveadm auth test aliceTest a username and password against passdb
doveadm user aliceShow userdb result: uid, gid, home, mail location
doveadm user '*'List all users (needs a userdb that supports iteration)
doveadm pw -s SHA512-CRYPTGenerate a password hash for SQL or passwd-file back ends
doveadm log errorsShow recent errors logged by Dovecot

Dovecot: mailboxes and sessions

CommandWhat it does
doveadm whoWho is logged in, from where, which protocol
doveadm kick aliceDisconnect all sessions for a user
doveadm mailbox list -u aliceList folders for a user
doveadm mailbox status -u alice messages INBOXCount messages in a folder
doveadm search -u alice mailbox INBOX from boss@example.comFind messages (returns GUIDs and UIDs)
doveadm expunge -u alice mailbox Trash savedbefore 30dPurge Trash older than 30 days
doveadm move -u alice Archive mailbox INBOX before 2025-01-01Move old mail to an Archive folder
doveadm force-resync -u alice INBOXRebuild indexes after corruption or manual file changes
doveadm quota get -u aliceShow quota usage (quota plugin enabled)
doveadm replicator statusReplication queue status (two-server setups)

Firewall and SELinux

CommandWhat it does
firewall-cmd --permanent --add-service=smtp --add-service=smtp-submission --add-service=imapsOpen 25, 587 and 993
firewall-cmd --permanent --add-service=smtpsOpen 465 (implicit TLS submission)
firewall-cmd --reload && firewall-cmd --list-servicesApply and verify
semanage port -l | grep -E 'smtp|pop|imap'Ports SELinux allows for mail daemons
semanage port -a -t smtp_port_t -p tcp 2525Allow Postfix on a non-standard port
ausearch -m AVC -ts recentRecent SELinux denials
getsebool -a | grep -E 'postfix|dovecot|mail'Mail-related SELinux booleans
restorecon -Rv /home/alice/MaildirFix labels after copying or restoring mail

Key file locations

PathPurpose
/etc/postfix/main.cfMain Postfix configuration
/etc/postfix/master.cfPostfix services (smtp, submission, smtps)
/etc/aliasesLocal aliases (rebuild with newaliases)
/var/spool/postfix/Postfix queue directories (incoming, active, deferred, hold)
/etc/dovecot/dovecot.confMain Dovecot configuration (includes conf.d/*.conf)
/etc/dovecot/conf.d/10-auth.confAuthentication mechanisms and back ends
/etc/dovecot/conf.d/10-mail.confmail_location and mailbox settings
/etc/dovecot/conf.d/10-master.confService listeners (LMTP, auth socket for Postfix)
/etc/dovecot/conf.d/10-ssl.confTLS certificate and key
/var/log/maillogMail log on EL9 and EL10 with rsyslog

Related posts

Leave a Reply

Your email address will not be published. Required fields are marked *