Clear / clean / empty the qmail queue

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

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://japanitup.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://japanitup.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 you can check out these links:
A reference for qmail users - qmail.org
A qmail tutorial site - Life With Qmail

Related posts

10 Responses to “Clear / clean / empty the qmail queue”


  1. 1 tapster

    thanks so much for this.. my server had run out of inodes and I discovered it was qmail with tens of thousands of file handles

    quick google and stumbled on your site, and the above worked a treat

    Im also a big fan of Japan, been a few times, and would love to live there one day

    thanks again

    t

  2. 2 Mike Pulli

    Thank you for the awesome utiltity to clear my qmail queue. I’m having a problem with a lot of spam getting through, not being rejected for some reason and it’s just building up in the queue and eventually crashing the smtp server hosted by qmail ( I think). Do you have any suggestions that I could use for my spam settings.. I’ve checked with the tech who “hold” my server and they say the spam settings I have are good.

    Any help you could provide would be awesome!

    Thanks. Mike

  3. 3 Steve

    tapster - I’m glad this helped you, and remember… Japan is here waiting for you.

    Mike - I’m glad this helped. For the spam, I’m not sure what you can do if your qmail queue is getting bogged down. Your hosting company should help you (even though they say your settings are fine). If you’re always getting the queue filled up there must be an issue on the server with something (vague I know).

    If it’s spam being sent to you and landing in your inbox you might look at having Spam Assassin installed. Here’s a wikipedia page about it. In the options you can mark spam suspect emails with [SPAM] in the subject and filter them to the junk mail box in Outlook, etc. Or you can have Google/Gmail handle it by using their service. Good luck!

  4. 4 bellablue

    THANK YOU SOOOO MUCH FOR THIS INFO - honestly having a dedicated server - the people running it are no help!!! thank you !!

  5. 5 bellablue

    ok - I am still thankful but now I anything I send just sits in que and wont send ??? what happened? nothing is sending - did it screw up my qmail?

  6. 6 Steve

    bellablue - I’m glad it helped the first time, but now it sits in the queue? That’s not good. I don’t know if you broke anything when you cleared the queue but I’m assuming you didn’t because it was full in the first place and may have had problems sending at that time. I’m not sure what the solution is to help you out but I can lead you in the right direction. Check out this post at Qmail Rocks and you can explore the rest of that site here:
    http://forum.qmailrocks.org/

    I know this is frustrating, so I wish you good luck!

  7. 7 Joe

    Hi,

    I just want to say that is the best script I have
    ever used….

    I have tried another command and it would just hang this worked and
    and completed in like 10 mins…

    Thanks,
    Joe

  8. 8 Steve

    Joe - I’m glad this worked for you.

  9. 9 solshark

    Thx so much!

  10. 10 Steve

    solshark - I’m glad this post could help!

Leave a Reply