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.

You can download it and view 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

Latest Comments
  1. newby March 8, 2012
  2. DanC July 29, 2011
  3. Ritesh July 27, 2011
    • Ritesh July 27, 2011
  4. tapster June 9, 2011
  5. Eric May 5, 2011
  6. Jani Joki April 25, 2011
  7. SumC April 23, 2011
  8. corn April 17, 2011
  9. Mike Pulli March 21, 2011
    • Admin (HowToHacks.com) March 22, 2011
  10. MohdYusuf March 17, 2011
    • Admin (HowToHacks.com) March 29, 2011

Leave a Reply

Your email address will not be published. Required fields are marked *