Guide updated on 29th of February 2016

Install and use qmqtool


Qmqtool - a qmail queue manipulation program geared towards the viewing and safe modification of the contents in a qmail queue

Qmqtool is a utility designed for viewing and safely modifying the contents of a qmail queue. It is extremely feature rich, with features including finding abusers, sorting messages by sender/sender's IP, showing stats, requeueing messages, queue consistency check, queue backup/restore, and others.

More info can be found HERE.

Configure it

cd /downloads/
tar zxvfp /downloads/qmqtool-1.14.tgz

cd /downloads/qmqtool-1.14/
./configure --perl=/usr/bin/perl --qmaildir=/var/qmail

You should have such result

found perl: /usr/bin/perl
found qmail directory: /var/qmail
qmqtool will be installed in: /usr/local/script
documentation will be installed in /usr/local/man

if any of these values need changing, try ./configure --help

Making sure this package is intact..
src/qmqtool syntax OK
...done.
Writing Makefile...

now type 'make' and then 'make install'

Compile it

make
make install

You should have such result

mkdir -p /usr/local/script
cp qmqtool /usr/local/script
chown 0 /usr/local/script/qmqtool
chmod 755 /usr/local/script/qmqtool
mkdir -p /usr/local/man/man8/
cp qmqtool.8 /usr/local/man/man8/
chown 0 /usr/local/man/man8/qmqtool.8
chmod 744 /usr/local/man/man8/qmqtool.8

ln -s /usr/local/script/qmqtool /usr/local/bin/qmqtool

Use it

        qmqtool version 1.14
        syntax: qmqtool [-l] [-L] [-R] [-S [-nN]] [-T] [-s] [-Q] [-c] [-r] [-i [-nN]] [-V]
                        [-E(A|R|L)] [-U(A|R|L)] [-vN [-w]] [-e(N|[-f 'STRING'][-oN])] [-u(N|[-f 'STRING'][-oN])]
                        [-d(N|[-f 'STRING'][-oN])] [-f 'STRING'] [-oN] [-B(b|r)] [-x(N|[-f 'STRING'][-oN])]

        -l              list messages in all parts of the queue
        -L              list messages with local recipients
        -R              list messages with remote recipients
        -T              list messages not completely processed
        -s              show statistical information
        -Q              be as quiet as possible (useful for snmp, cron, and such)
        -V              be more verbose
        -B
          b             Backup queue into /var/qmail/queue.backup/
          r             Restore backup from /var/qmail/queue.backup/
        -c              check queue consitancy
        -r              repair queue (by deleting fragments) found by checking queue consistancy
        -i              show how many messages are queued per ip address
           -nN          pay attention to the Nth last smtp-hop
        -S              show how many bytes are queued per ip address
        -e              expire message
                        may specify N (multiples may be comma separated), or -f 'STRING' and/or -o N
        -u              unexpire message
                        may specify N (multiples may be comma separated), or -f 'STRING' and/or -o N
        -d              delete message
                        may specify N (multiples may be comma separated), or -f 'STRING' and/or -o N
        -E              expire messages in [A]ll, [R]emote, or [L]ocal queues
        -U              unexpire messages in [A]ll, [R]emote, or [L]ocal queues
        -v
          N             view first 100 lines of message number N
          N -w          view whole message N
        -f 'STRING'     display comma separated list of message number(s) containing STRING.
                        prints 0 if no matches are found.
        -o N            display comma separated list of message number(s) older than N hours.
                        prints 0 if no matches are found.
        -x N            prints extended information on message N.  format identical to -l.
                        may specify N (multiples may be comma separated), or -f 'STRING' and/or -o N

Usage samples :

List all messages in the queue having the subject "XXX" (case insensitive)
qmqtool -f '/^subject: xxx/i'

Delete all messages in the queue having the subject "XXX" (case insensitive)
qmqtool -d -f '/^subject: XXX/i'
qmailctl restart

Delete all messages in the queue from user "XXX" (case insensitive)
qmqtool -d -f '/^From: XXX/i'
qmailctl restart

Who are the top 20 senders for the remote queue
qmqtool -R | grep "From: " | sort | uniq -c | sort -rn | head -20

Who are the top 20 recipients of the remote queue
qmqtool -R | grep "To: " | sort | uniq -c | sort -rn | head -20
qmqtool -R | grep "Envelope Recipient: " | sort | uniq -c | sort -rn | head -20

What are the top 20 subjects of the remote queue
qmqtool -R | grep "Subject: " | sort | uniq -c | sort -rn | head -20

What domains are being sent the most mail from the server
qmqtool -R | grep "To: " | cut -d @ -f2 | tr -d '>' | sort | uniq -c | sort -rn | head -20
qmqtool -R | grep "Envelope Recipient: " | cut -d @ -f2 | awk '{print $1}' | tr -d '>' | sort | uniq -c | sort -rn | head -20

Who are the top receivers for the local queue
qmqtool -L | grep "To: " | sort | uniq -c | sort -rn | head -20
qmqtool -L | grep "Envelope Recipient: " | sort | uniq -c | sort -rn | head -20

What domains are have the most mail in the local queue
qmqtool -L | grep "To: " | cut -d @ -f2 | tr -d '>' | sort | uniq -c | sort -rn | head -20
qmqtool -L | grep "Envelope Recipient: " | cut -d @ -f2 | awk '{print $1}'

Who most of my remotely queued messages are destined for ?
qmqtool -R | awk '/Recipient:/ { print $3 }' | sort | uniq -c | sort -n

How can I expire messages with a subject of "Failure Notice" that are have been queued for 18+ hours ?
qmqtool -V -e -o 18 -f '^Subject: Failure Notice'

List of optional features


Users comments