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

Tags: , , ,
21 Responses to “Clear / clean / empty the qmail queue”
  1. tapster says:

    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. Mike Pulli says:

    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. Steve says:

    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. bellablue says:

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

  5. bellablue says:

    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. Steve says:

    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. Joe says:

    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. Steve says:

    Joe – I’m glad this worked for you.

  9. Steve says:

    solshark – I’m glad this post could help!

  10. Eric says:

    This only works if you have a small amount of mail in your queue. If you have enough e-mail to warrant the use of this script:
    ./qmailclear.sh: /bin/rm: Argument list too long

    One example : ls 15 | wc -l
    56193

    Try this (replace where necessary)

    #!/bin/bash

    QMAIL_QUEUE=/{path-to-qmail-queue}/queue

    /{path-to-qmail-init-scripts}/qmail stop

    for foo in info mess remote intd local todo
    do
    for bar in `ls $QMAIL_QUEUE/$foo`
    do
    cd $QMAIL_QUEUE/$foo/$bar
    ls | xargs rm
    done

    done

    /{path-to-qmail-init-scripts}/qmail start

  11. Tony says:

    This is best utility! Thank you for the kick ass utiltity to clear my qmail queue. It’s the quickest and easiest way to clear it.

  12. Scott says:

    Steve -

    Thanks so much for this. Worked like a charm.

    - Scott

  13. alec says:

    Hi. My server is a victim of Back Scatter. The only thing I can tell is to compile a chkusr patch with qmail and plesk and it would fix my problem. However, the compile fails due to complications with plesk. Do you know of another way to handle this?
    Someone told me that using postfix instead of qmail would work but backscatter is REALLY BAD. I get up to 3 spams a second even with all services turned off. They just keep coming on in!
    Any help greatly appreciated.

  14. bill Rogers says:

    I use the solution you are whowing but when I run the qmailclear, I get it. the queue is not clear. please help

    messages in queue: 479660
    messages in queue but not yet preprocessed: 2
    [root@ip-97-74-112-68 ~]# sh qmailclear.sh
    Stopping Qmail – MinisterAlan
    Stopping : Clearing the Mail Queue
    qmailclear.sh: line 11: //bin/rm: Argument list too long
    qmailclear.sh: line 13: //bin/rm: Argument list too long
    qmailclear.sh: line 15: //bin/rm: Argument list too long
    qmailclear.sh: line 17: //bin/rm: Argument list too long
    qmailclear.sh: line 19: //bin/rm: Argument list too long
    qmailclear.sh: line 21: //bin/rm: Argument list too long
    qmailclear.sh: line 23: //bin/rm: Argument list too long
    qmailclear.sh: line 25: //bin/rm: Argument list too long
    qmailclear.sh: line 27: //bin/rm: Argument list too long
    qmailclear.sh: line 29: //bin/rm: Argument list too long
    qmailclear.sh: line 31: //bin/rm: Argument list too long
    qmailclear.sh: line 33: //bin/rm: Argument list too long
    qmailclear.sh: line 35: //bin/rm: Argument list too long
    qmailclear.sh: line 37: //bin/rm: Argument list too long
    qmailclear.sh: line 39: //bin/rm: Argument list too long
    qmailclear.sh: line 41: //bin/rm: Argument list too long
    qmailclear.sh: line 43: //bin/rm: Argument list too long
    qmailclear.sh: line 45: //bin/rm: Argument list too long
    qmailclear.sh: line 47: //bin/rm: Argument list too long
    qmailclear.sh: line 49: //bin/rm: Argument list too long
    qmailclear.sh: line 51: //bin/rm: Argument list too long
    qmailclear.sh: line 53: //bin/rm: Argument list too long
    qmailclear.sh: line 55: //bin/rm: Argument list too long
    Info folder clean, clearing mess folder
    qmailclear.sh: line 61: //bin/rm: Argument list too long
    qmailclear.sh: line 63: //bin/rm: Argument list too long
    qmailclear.sh: line 65: //bin/rm: Argument list too long
    qmailclear.sh: line 67: //bin/rm: Argument list too long
    qmailclear.sh: line 69: //bin/rm: Argument list too long
    qmailclear.sh: line 71: //bin/rm: Argument list too long
    qmailclear.sh: line 73: //bin/rm: Argument list too long
    qmailclear.sh: line 75: //bin/rm: Argument list too long
    qmailclear.sh: line 77: //bin/rm: Argument list too long
    qmailclear.sh: line 79: //bin/rm: Argument list too long
    qmailclear.sh: line 81: //bin/rm: Argument list too long
    qmailclear.sh: line 83: //bin/rm: Argument list too long
    qmailclear.sh: line 85: //bin/rm: Argument list too long
    qmailclear.sh: line 87: //bin/rm: Argument list too long
    qmailclear.sh: line 89: //bin/rm: Argument list too long
    qmailclear.sh: line 91: //bin/rm: Argument list too long
    qmailclear.sh: line 93: //bin/rm: Argument list too long
    qmailclear.sh: line 95: //bin/rm: Argument list too long
    qmailclear.sh: line 97: //bin/rm: Argument list too long
    qmailclear.sh: line 99: //bin/rm: Argument list too long
    qmailclear.sh: line 101: //bin/rm: Argument list too long
    qmailclear.sh: line 103: //bin/rm: Argument list too long
    qmailclear.sh: line 105: //bin/rm: Argument list too long
    Mess folder clean, clearing remote folder
    qmailclear.sh: line 111: //bin/rm: Argument list too long
    qmailclear.sh: line 113: //bin/rm: Argument list too long
    qmailclear.sh: line 115: //bin/rm: Argument list too long
    qmailclear.sh: line 117: //bin/rm: Argument list too long
    qmailclear.sh: line 119: //bin/rm: Argument list too long
    qmailclear.sh: line 121: //bin/rm: Argument list too long
    qmailclear.sh: line 123: //bin/rm: Argument list too long
    qmailclear.sh: line 125: //bin/rm: Argument list too long
    qmailclear.sh: line 127: //bin/rm: Argument list too long
    qmailclear.sh: line 129: //bin/rm: Argument list too long
    qmailclear.sh: line 131: //bin/rm: Argument list too long
    qmailclear.sh: line 133: //bin/rm: Argument list too long
    qmailclear.sh: line 135: //bin/rm: Argument list too long
    qmailclear.sh: line 137: //bin/rm: Argument list too long
    qmailclear.sh: line 139: //bin/rm: Argument list too long
    qmailclear.sh: line 141: //bin/rm: Argument list too long
    qmailclear.sh: line 143: //bin/rm: Argument list too long
    qmailclear.sh: line 145: //bin/rm: Argument list too long
    qmailclear.sh: line 147: //bin/rm: Argument list too long
    qmailclear.sh: line 149: //bin/rm: Argument list too long
    qmailclear.sh: line 151: //bin/rm: Argument list too long
    qmailclear.sh: line 153: //bin/rm: Argument list too long
    qmailclear.sh: line 155: //bin/rm: Argument list too long
    Remote folder clean, clearing intd folder
    Intd folder clean, clearing local folder
    Local folder clean, clearing todo folder
    Mail queue cleaned
    Re-Start Qmail Now !
    Starting qmail:

    • Steve says:

      I bet this is driving you nuts! The only solution I have for “Argument list too long” is the one listed above in the original post.

  15. John C says:

    what can I say? Thank you x 10. We had been hacked and were left with a massive mail queue. I can go to bed to night and sleep!

  16. Jani Joki says:

    Anyone ever heard of find?

    cd /var/qmail/queue &&
    find info mess remote intd local todo -type f -exec rm {} \;

  17. Ritesh says:

    We have just under 500,000 in the queue… am running the qmailclean due to the size of the queue. it has been like 20mins… will wait and see how much longer it takes. will update when done.

  18. Ritesh says:

    took just over 40mins and the queue has been cleared. had to restart Qmail though as it had somehow stopped.

    good stuff.

  19.  
Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>
Want an avatar/icon by your name? Click here to learn how.