Working with the mail queue in Qmail

Qmail is not the last word in mail delivery technology, but this smtp daemon is still very widespread. In particular many servers with the Plesk panel use exactly Qmail.

To see the list of messages waiting to be sent (to look at the delivery queue) you can use the following utility:

/var/qmail/bin/qmail-qread

The following script helps to count the number of messages in the queue:

/var/qmail/bin/qmail-qstat

Things are a bit more complicated with reading the contents of the messages. The thing is that a message is spread over three files in the following folders:

  • /var/qmail/queue/info/
  • /var/qmail/queue/remote/
  • /var/qmail/queue/mess/

The file name is the message id. The message IDs are printed in the output of the first command. As a rule it returns something in this style:

6 Jan 2016 09:18:13 GMT #**10817428** 642 <[email protected]>  
remote [email protected]

The message ID is in bold.

You can read the contents of the message with some extra moves:

find /var/qmail/queue -name NNNN -exec cat {} \; | less

NNNN is the message id.

The following loop prints the list of scripts that initiated the sending of the messages in the queue:

for f in $(/var/qmail/bin/qmail-qread |cut -d "#" -f 2 |awk '{print $1}' |sort -u);
do
   find /var/qmail/queue -name $f |xargs grep "X-PHP-Originating-Script";
done |cut -d ":" -f 4 |sort -u

Tags:

Categories:

Updated: