clear qmail queue of 201000 messages?

Posted on 2009-02-20
Last Modified: 2013-12-02
how do I use telnet (ssh2) to empty all messages in my mail queue? What is the command for this? so far I have done these commands..
cd /var/qmail/queue

messages in queue: 201578

what is next to empty it?
Question by:yglobal
    LVL 20

    Accepted Solution

    Sounds like you've had some problems!

    OK -- first a caveat (and a potential "self-fix"), then a brute-force answer:

    But first, understand that the QMail Queue is multi-part and uses mutual-exclusion flags to manage the Queue.... so you shouldn't try to just remove the entries on the fly.
    Secondly, if you've "fixed" what filled up your queue to begin with, it should clean itself out in about 4 days (or whatever the value of /var/qmail/control/queuelifetime happens to be). The messages "caught" in your Queue are just messages that are being rejected by the recipient (which could be for a wide variety of reasons).

    So here are your ways to clean out the QMail Queue:

    1) The "BEST" way to clear out the queue without losing anything "legitimate" in there is to simply shorten the period of time messages are allowed to wallow in the Queue. The example below will change your queue lifetime to 10 minutes (vs. 4 days), however messages won't be removed until one last-ditch effort has been made to deliver them -- so the effect takes time!

    # echo 600 > /var/qmail/control/queuelifetime
    # pkill -ALRM qmail-send

    ... wait a day or so for ALL "bad" messages to be cleared out, then reset back to 4 days

    # echo 345600 > /var/qmail/control/queuelifetime
     # pkill -ALRM qmail-send
    You can periodically do a qmailctl queue and you'll see the number drop (assuming your QMail install uses qmailctl.

    2) OK... suppose you don't care about any valid messages that may yet be in the queue... you just want to start fresh... here ya go.
    First, we'll note that ALL messages in the QMail Queue are located in multiple files in multiple directories -- so we can't just start deleting files... we need to STOP QMail first.
    Next, we don't want to have to type in the names of over 100 folders, so we'll use FIND instead -- noting that the file names for all messages in the QMail Queue are just numbers.
    Here goes:

    # qmailctl stop # Note: this assumes you're using a QMail installation with the qmailctl script... If not, shut down QMail your own way
    ... use whatever means to make SURE qmail-send is stopped (as well as qmail-remote & qmail-local)
    # cd /var/qmail/queue # Note: this assumes that this is your Queue location -- you may need to adjust for your own install...
    # find . -type f -name '[0-9]*' -exec rm -f '{}' \;
    # qmailctl start
    To re-iterate -- the above cleans out EVERY message in the queue -- the good, the bad, & the ugly, but leaves the mutex locks alone.

    I hope this helps!

    LVL 17

    Expert Comment

    why do you want to use telnet to clear the queue... there is a very easy way to get rid of the emails man..
    what is the server? exch 2003 or exch 2007 ???

    LVL 17

    Expert Comment

    if its exchagne 2003 then stop the smtp service... open your windows explorer and go to location of Mailroot folder.. and rename it to MailrootOld. and then restart the smtp service...
    check the queue.. now u can go and delete the old one...

    if 2007 then stop the transport service locate the data folder and rename it to dataOld. restart the transport service... check the queue... and now delete the old data folder

    Once we restart the smtp / transport servic IT Creates a new Folder of that name.. this will be clear !!!

    - I hope you got the issue cleard this way... this is very simple and the best....

    LVL 20

    Expert Comment

    by:Daniel McAllister
    no offense, but given that
     a) the poster has already mentioned that he's changing directory to /var/qmail/queue, and running a qmail-specific scripts, and
     b) the question is posted (cross-posted) into a QMail Zone

    ...exactly WHAT would possess you to think that he is running Exchange? Me thinks you've been drinking Bill Gate's KoolAid again, and believing that the whole world runs Microsoft softare (except for a small handful of Linux geeks).

    The commands I listed above are shell commands that should be run as ROOT (non-privileged users will not be able to execute them as shown). And if you're telnetting into your system as root, shame on you... use SSH (instead of telnet), and login as an un-privileged user, then SU to the ROOT user... If you WANT (read: insist) on logging in directly as ROOT, at least use SSH and disable your telnet server... telnet is TOTALLY insecure!

    Good Luck!


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Secure Shell (SSH) is a network protocol for secure data communication, mainly used to administer remote Unix / Linux servers via command line. But it also allows the user to open a secure tunnel between a client and a server where he can send any k…
    Automapping, a wonderful feature with Exchange 2010 (SP2 onwards I believe), allows additional/Shared mailboxes that a user has access to be automatically mapped on Outlook client, simplifying the process by adding them while Outlook launches. Ho…
    The basic steps you have just learned will be implemented in this video. The basic steps are shown to configure an Exchange DAG in a live working Exchange Server Environment and manage the same (Exchange Server 2010 Software is used in a Windows Ser…
    Viewers will learn how to properly install and use Secure Shell (SSH) to work on projects or homework remotely. Download Secure Shell: Follow basic installation instructions: Open Secure Shell and use "Quick Connect" to enter credentials includi…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now