Qmail : Removing emails from queue having the specified Subject

Identify the email header id from the queued emails.. I’m goingg to use “qmail-qstat” command to know the email header. ID will starts with # symbal eg. #1445826
[root@mail4 ~]# /var/qmail/bin/qmail-qread | more
4 Dec 2012 17:04:33 GMT #1442054 7146
remote admin@sample.com
4 Dec 2012 17:06:16 GMT #1442974 7048
remote admin@samplesouth.net
4 Dec 2012 17:08:47 GMT #1444078 7064
remote admin@sampleotmail.com

b. Find the messages associated with this email header.
[root@mail4 ~]# find /var/qmail/queue -iname 1445826
/var/qmail/queue/mess/0/1445826
/var/qmail/queue/info/0/1445826
/var/qmail/queue/remote/0/1445826

Now open the file to read the email body. Choose the file part contains message (/var/qmail/queue/mess/0/1445826)
[root@mail4 ~]# cat /var/qmail/queue/mess/0/1445826 | more
Received: (qmail 20473 invoked by uid 0); 4 Dec 2012 17:12:24 -0000
Date: 4 Dec 2012 17:12:24 -0000
Message-ID: <20121204171224.20472.qmail@mail4.test.com>
To: apet@aximo.com
Subject: Better than EQP
From: Uniline Promo Inc
Reply-To: Uniline Promo Inc
MIME-Version: 1.0
Content-type: multipart/alternative; boundary=”_d96476de58f15ff5cda2ac8a00860156″
This is a multi-part message in MIME format.
–_d96476de58f15ff5cda2ac8a00860156
Content-Type: text/plain; charset=”iso-8859-1″
Content-Transfer-Encoding: 7bit

Now you can see the email subject from the email message part. You may need to install another third party tool to remove the email having the specified the Subject from the queue.

C. Install qmail-remove script
Download this package from http://www.linuxmagic.com/opensource/qmail/qmail-remove/qmail-remove-0.95.tar.gz
#wget http://www.linuxmagic.com/opensource/qmail/qmail-remove/qmail-remove-0.95.tar.gz
#tar -zxvf mail-remove-0.95.tar.gz
#cd mail-remove-0.95
#make && make install
#ln -s /usr/local/sbin/qmail-remove /usr/bin/qmail-remove
#mkdir -p /var/qmail/queue/yanked/

/var/qmail/queue/yanked/ –> This folder would have store all the files those are moved through this script.

D. Delete the specified emails having the same subject
#/etc/init.d/qmail stop
#qmail-remove -r -p “email subject name”

How to check the email sending statistics

[root@mail4 yanked]# /var/qmail/bin/qmail-qstat
messages in queue: 30835
messages in queue but not yet preprocessed: 230
[root@mail4 yanked]#

If you want to remove all the email from a particular user “spamsender@serveridol.com”, just execute the command as shown below
[root@rc-025 test]#qmail-remove -r -p “spamsender@serveridol.com”

Also I found another useful tool (qmHandle) for listing the email headers including sender,receiver address along with the email subject. So that we can identify the whether the email is spam or not and also we can use these information for pattern match deletion.

[root@rc-025 test]#http://nchc.dl.sourceforge.net/project/qmhandle/qmhandle-1.3/qmhandle-1.3.2/qmhandle-1.3.2.tar.gz
[root@rc-025 test]# tar -zxvf qmhandle-1.3.2.tar.gz && cd qmhandle-1.3.2
[root@rc-025 qmhandle-1.3.2]# cp qmHandle /usr/bin

How to list the Queued emails
[root@rc-025 test]# qmHandle -R
402725179 (9, 9/402725179)
Return-path: kathy@asd.com
From: Kathy Keeton
To: “themoonga5@ail.com” Subject: Cheer registration
Date: Wed, 3 Apr 2013 08:42:18 -0400
Size: 1147 bytes
Total messages: 1
Messages with local recipients: 0
Messages with remote recipients: 1
Messages with bounces: 0
Messages in preprocess: 0

Reviewing the queued emails [How to store all queued email informations before delete]
[root@rc-025 test]#qmHandle -R > /tmp/remotequeue.txt