How to clear the Qmail Queue (clean & delete it quickly)

Awe shiznit!! Is your qmail queue on your server out of control? Look no further! Here’s a quick and easy way to clear, clean, or empty your qmail queue.

Clear & Clean Qmail Queue Completely, Safely & Fast!

This script should not remove anything it should not remove, and it should clear all e-mail from your qmail queue safely so you can start sending mail normally again. (This is for qmail only and not a solution for any other mail programs.) You’re going to need ssh access and an ssh program like putty or putty portable.

Let’s get busy with the Qmail Clear script:

  1. Log into your server through ssh
  2. type this:
    su –
  3. type this:
    wget http://www.howtohacks.com/scripts/qmailclear.sh
  4. type this:
    sh qmailclear.sh or sh ./qmailclear.sh
  5. done.

I took the downloadable script down so you’ll need to write it yourself, but just as a quick summary so you know what it’s doing, the Qmail Clear script looks like this:

echo Cleaning Queue
mv /var/qmail/queue/lock /root/
cd /var/qmail/queue; find . -type f -exec rm -f ‘{}’ \;
mv /root/lock /var/qmail/queue/
echo Queue is now Clean

If this didn’t do the trick and you’re receiving oversized file truncating errors (or “Argument list too long”) then you should use this more intense script. It will take longer but it will get the job done.

Let’s get busy with the Qmail Clean script :

  1. Log into your server through ssh
  2. type this:
    su –
  3. type this:
    wget http://www.howtohacks.com/scripts/qmailclean.sh
  4. type this:
    sh qmailclean.sh or sh ./qmailclean.sh
  5. done.

DO NOT restart any process. DO NOT reboot the server. DO NOT do anything until the script says it is done. If you restart a process, etc, it will break qmail and that’s no fun. Just run the script until it’s complete.

You can download the script and view all of the code yourself, but here’s a quick summary of the main lines of code so you know what’s taking place when running the Qmail Clean script:

echo “Stopping Qmail”
/etc/init.d/qmail stop
echo “Clearing the Mail Queue”
cd /var/qmail/queue/info
rm -rf blah blah blah
echo “Info folder clean, clearing mess folder”
cd /var/qmail/queue/mess
rm -rf blah blah blah
echo “Mess folder clean, clearing remote folder”
cd /var/qmail/queue/remote
rm -rf blah blah blah
echo “Remote folder clean, clearing intd folder”
cd /var/qmail/queue/intd
rm -rf blah blah blah
echo “Intd folder clean, clearing local folder”
cd /var/qmail/queue/local
rm -rf blah blah blah
echo “Local folder clean, clearing todo folder”
cd /var/qmail/queue/todo
rm -rf blah blah blah
echo “Mail queue cleaned”
echo “Restarting Qmail Now”
/etc/init.d/qmail start
echo “Qmail Started!”
echo “Done!”

If you’re interested in reading more about Qmail I recommend this book Qmail book and also these links:
A reference for qmail users – qmail.org
A qmail tutorial site – Life With Qmail

How to empty the qmail queue

To clear all messages from the queue the first step is you must shut down qmail. Here are the SSH commands for that.

  • Using qmail-rocks scripts:
    /etc/rc.d/qmail stop
  • Or you can try the following
    qmailctl stop
  • Or you can try this
    init.d/qmail stop

To clear the qmail queue, use the following SSH commands to change to the queue directory and clear the queue.

  • cd /var/qmail/queue
  • find intd todo local remote mess info bounce -type f -print |xargs rm

After it’s clear you can start qmail back up using a similar command that stopped the service, but say start.

  • Using qmail-rocks scripts:
    /etc/rc.d/qmail start
  • Or you can try the following
    qmailctl start
  • Or you can try this
    init.d/qmail start

Now the queue should be empty!

For learning the ins and outs of Qmail I recommend this Qmail book