Manage the Qmail mail queue

Want to help support this blog? Try out Oh Dear, the best all-in-one monitoring tool for your entire website, co-founded by me (the guy that wrote this blogpost). Start with a 10-day trial, no strings attached.

We offer uptime monitoring, SSL checks, broken links checking, performance & cronjob monitoring, branded status pages & so much more. Try us out today!

Profile image of Mattias Geniar

Mattias Geniar, June 04, 2008

Follow me on Twitter as @mattiasgeniar

Ever used qmail? Ever had a mail stuck in the queue that just wouldn’t send?

Then you might want to give qmHandle a try. It’s a small tool you’ll need to download (~16KB), and it’ll save you quite some time.

Running “qmHandle -l” lists the current queue. Nothing special about that, running “/var/qmail/bin/qmail-qstat” will do the same. Then how do you send the mails stuck in the queue? The logs won’t tell you the reason why they’re still in there. Running “qmHandle -a” will force the mails in queue to be sent. If for some reason this still fails, the mails will remain in queue.

Now try deleting a mail (or a series of mails) from the queue, based on – let’s say – the subject. Now it gets harder if you want to use qmail’s built-in tools.

qmHandle simplifies this. Running the command “qmHandle -S'Viagra Penis Enlargments' " will delete all messages from the queue, where the subject contains the string contained in single quotes (note: the single quotes have to be entered directly after -S, there can be no space in between).

qmHandle has a lot more functionality, which you can discover by typing “qmHandle”. It’ll give you an output as follows:

Available parameters:

-a     : try to send queued messages now (qmail must be running)
-l     : list message queues
-L     : list local message queue
-R     : list remote message queue
-s     : show some statistics
-mN    : display message number N
-dN    : delete message number N
-Stext : delete all messages that have/contain text as Subject
-D     : delete all messages in the queue (local and remote)
-V     : print program version
Additional (optional) parameters:
-c     : display colored output
-N     : list message numbers only

(to be used either with -l, -L or -R)

You can view/delete multiple message i.e. -d123 -v456 -d567

Just explore qmHandle a bit, you’ll find it quite nice and invaluable when working with a qmail-enabled system.



Want to subscribe to the cron.weekly newsletter?

I write a weekly-ish newsletter on Linux, open source & webdevelopment called cron.weekly.

It features the latest news, guides & tutorials and new open source projects. You can sign up via email below.

No spam. Just some good, practical Linux & open source content.