[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1299
  • Last Modified:

clear qmail queue of 201000 messages?

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?
  • 2
  • 2
1 Solution
Daniel McAllisterPresident, IT4SOHO, LLCCommented:
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!

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 ???

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....

Daniel McAllisterPresident, IT4SOHO, LLCCommented:
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!


Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now