Delete Qmail Server
messages Queue
qmail is a mail transfer agent that runs on Unix. It was more
secure replacement for the popular Sendmail program. The author
offered a $500 prize for the first person to publish a
verifiable security hole in the latest version of the software.
This is a useful thing to do in a number of situations. For
instance, if you are hit with a spamming attack, you can
temporarily instate a second Qmail installation (once the spam
run is finished), allow it to take over mail receipt,and then
use this tool to clean the offending mails out of the queue
before switching over to the main Qmail installation once again.
Occasionally, viruses will get past scanners before the
signatures get updated; if they exist in large numbers, it is
often practical to stop the Qmail install briefly in order to
clean out all messages containing a signature related to the
virus.
Whatever the reason to pull items from your mail queue, this
program will delete them in such a manner that will let you
restore them easily.
Here we are going to see different Technics how to delete or
remove your qmail server queue
Qmail-Remove
This is definitely my first choice.Qmail-Remove will remove
messages containing a particular string from your Qmail queue.
Mails are *not* deleted from the queue! They are only stored,
temporarily, in $qmail-queue/yanked/, where you can view them
individually and restore them back to the queue manually. There
is currently no support for restoring them automatically.
By default, Qmail-Remove assumes that your Qmail queue is stored
in /var/qmail/queue, but this can be changed with a command line
option. Similarly, Qmail-Remove assumes that your queue “split”
is 23 by default, among other things.
If you want to check your qmail queue using the following
command
# /var/qmail/bin/qmail-qstat
Output looks like
messages in queue: 567154
messages in queue but not yet preprocessed: 3
Install Qmail-Remove
First you need to download latest version from
here current version is Qmail-Remove 0.95
Download using the following command
#wget http://www.linuxmagic.com/opensource/qmail/qmail-remove/qmail-remove-0.95.tar.gz
Now you have qmail-remove-0.95.tar.gz file and now you need to
extract using the following command
#tar -zxvf qmail-remove-0.95.tar.gz
Now you should have qmail-remove-0.95 folder go in to the
directory and run the following commands
#make
#make install
This will complete the installation.
Now you need to create a directory named “yanked” in the qmail
queue directory you intend to use before using this program.
#mkdir /var/qmail/queue/yanked
Using qmail-remove
Syntax
qmail-remove [options]
Available options
-e use extended POSIX regular expressions
-h, -? this help message
-i search case insensitively [default: case sensitive]
-n limit our search to the first bytes of each file
-p specify the pattern to search for
-q specify the base qmail queue dir [default: /var/qmail/queue]
-r actually remove files, without this we’ll only print them
-s specify your conf-split value if non-standard [default: 23]
-v increase verbosity (can be used more than once)
-y directory to put files yanked from the queue [default:
/yanked]
-X modify timestamp on matching files, to make qmail expire mail
is the number of seconds we want to move the file into the
past.specifying a value of 0 causes this to default to (604800)
-x modify timestamp on matching files, to make qmail expire mail
is a date/time string in the format of output of the “date”
program.
Examples for qmail-remove
Before doing any thing related to qmail queue you need to stop
the qmail service using the following command
#/etc/init.d/qmail stop
To delete mails from Que,
#qmail-remove -r -p
# qmail-remove -r -p gtre.ac.net
324001: yes
moved mess/0/324001 to yanked/324001.mess
moved remote/0/324001 to yanked/324001.remote
moved info/0/324001 to yanked/324001.info
324024: yes
moved mess/0/324024 to yanked/324024.mess
moved remote/0/324024 to yanked/324024.remote
moved info/0/324024 to yanked/324024.info
This will remove all emails in que with “gtre.ac.net” in it and
place it in /var/qmail/queue/yanked folder.
qmhandle
qmHandle is a simple program which allows you to view and manage
the qmail message queue.
qmHandle Advantages
You can read the qmail queue, like you do with the qmail-qread
program.
However, the output of this program is improved over qmail-qread,
with the output of the message subjects and color capabilities;
You can print queue statistics, like qmail-qstat, with color
capabilities;
You can view a message in the queue;
You can remove one or more messages from the queue;
Written in Perl, and therefore easily customizable and truly
multiplatform.
Install qmhandle
First you need to download latest version from
here and
the current version is qmhandle-1.2.0
Download using the following command
#wget http://mesh.dl.sourceforge.net/sourceforge/qmhandle/qmhandle-1.2.0.tar.gz
Now you have qmhandle-1.2.0.tar.gz file you need to extract
using the following command
#tar xzvf qmhandle-1.2.0.tar.gz
You should be having qmhandle-1.2.0 folder go in to the folder
and you need to edit the qmHandle file to configure the
following settings
my ($queue) = ‘/var/qmail/queue/’;
my ($stopqmail) = ‘/etc/init.d/qmail stop’;
my ($startqmail) = “/etc/init.d/qmail start”;
my ($pidcmd) = ‘pidof qmail-send’;
Using qmHandle
Available options for qmHandle
Available parameters are:
-a : try to send all queued messages now (qmail
must be running)
-l : list message queues
-L : list local message queue
-R : list remote message queue
-s : show some statistics
-vN : display message number N
-dN : delete message number N
-Stext : delete all messages that have/contain text as Subject
-D : delete all messages in the queue (local & remote)
-V : print program version
Additional (optional) parameters are:
-c : display colored output
-N : list message numbers only (to be used either with -l, -L or
-R)
Examples
list message queues
#qmHandle -l
delete all messages that have/contain text as Subject
#qmHandle -l -S yahoo.com.tw
Other Solutions
1)You can edit the /var/qmail/control/queuelifetime file this is
the file to control how long a message stays in a queue.Just put
a number (to represent seconds)in this file.By default 86400 sec
Will keep the mail for 1 day and expire after that.Here you can
change this value to 1 and restart your qmail server it should
clear your qmail queue.
2)Deleting mails from qmail queue
Following commands can delete all mails from your qmail mail
server queue.
qmailctl stop
find /var/qmail/queue/mess -type f -exec rm {} \;
find /var/qmail/queue/info -type f -exec rm {} \;
find /var/qmail/queue/local -type f -exec rm {} \;
find /var/qmail/queue/intd -type f -exec rm {} \;
find /var/qmail/queue/todo -type f -exec rm {} \;
find /var/qmail/queue/remote -type f -exec rm {} \;
qmailctl start