List of handy commands for different mail server software
Contents
Generic Commands
- List mail queue:
mailq
- 10 top email sender addresses (may take a while to run):
mailq|grep -i ^[a-z]|grep -Ev 'MAILER'|awk '{print $7}'|sort|uniq -c|sort -nr|head
Sendmail
- List mail queue:
sendmail -bp
- Flush mail queue:
sendmail -q
- Delete message with ID XXXXXX from mail queue (dirty hack):
rm /var/spool/mqueue/*XXXXXX*
- Example command to remove mail from the queue for a specific user (USER in this example):
DON'T USE THIS UNLESS YOU KNOW WHAT YOU ARE DOING!
mailq|grep USER|while read id crap; do rm /var/spool/mqueue/*$id*;done
Postfix
- List mail queue:
postqueue -p
- Flush mail queue:
postqueue -f
- View contents of message with ID XXXXXX in mail queue:
postcat -q XXXXXX
- Delete message with ID XXXXXX from queue
postsuper -d XXXXXX
Example command to remove all messages from mail queue originating from one users (in this example USER@SERVER.anchor.net.au):
mailq|grep USER@SERVER.anchor.net.au|cut -f1 -d' '|tr -d '*'|postsuper -d -
This may not always get 100% of the messages as sometimes the message ID is on the previous line, in which case something the following will nail them:
mailq|grep USER -B2|grep MAILER|cut -f1 -d' ' |tr -d '*'|postsuper -d -
Qmail
- List queue:
qmailctl queue
- Flush mail queue:
qmailctl doqueue
If the qmail queue gets broken from the file system filling up, you will need to download and run: http://pyropus.ca/software/queue-repair/
