Thursday, December 8, 2011

How to remove the spam mails from qmail queue

Advertisements


How to remove spam mails from qmail mail queue

This post helps you to remove spam mails containing a string (subject) or from a particular user from the qmail mail queue. You have to install a open source

software qmail-remove.

Go to the directory /usr/local/src
[root@host ~]# cd /usr/local/src

Download the qmail-remove package
[root@host ~]# wget http://www.linuxmagic.com/opensource/qmail/qmail-remove/qmail-remove-0.95.tar.gz

Untar the package
[root@host ~]# tar xvzf qmail-remove-0.95.tar.gz

cd to the untared directory
[root@host ~]# cd qmail-remove-0.95/

compile
[root@host ~]# make

Install
[root@host ~]# make install

You can check the options with -h option
[root@host ~]# qmail-remove -h

Now the package is installed but you have to create a yanked directory to store the mails you are removing. You have to create it in the qmail base

directory. In this case it is /var/qmail/queue/ yours may differ.
[root@host ~]# cd /var/qmail/queue/
[root@host ~]# mkdir yanked

And before running the commands using this package you must stop qmail
[root@host ~]# /etc/init.d/qmail stop

There is one helpful tool with you can count and list the spam mails. Install it. You can get the directions from here
http://www.atomicorp.com/wiki/index.php/Spam

You can use -s option to get the total no.of spam mails in queue
[root@host ~]# /usr/bin/qmhandle.pl -s
Total messages: 253998
Messages with local recipients: 17
Messages with remote recipients: 253965
Messages with bounces: 1
Messages in preprocess: 16
[root@host ~]# /usr/bin/qmhandle.pl -s
Total messages: 185000
Messages with local recipients: 17
Messages with remote recipients: 184962
Messages with bounces: 1
Messages in preprocess: 20
[root@host ~]#

You can use -l option to list the spam mails in queue
[root@host ~]# /usr/bin/qmhandle.pl -l

You can read a message using the option -m
[root@host ~]# /usr/bin/qmhandle.pl -m22616314
 --------------
MESSAGE NUMBER 22616314
 --------------
Received: (qmail 25932 invoked by uid 502); 7 Dec 2011 12:17:40 +1100
Date: 7 Dec 2011 12:17:40 +1100
Message-ID: <20111207011740.25927.qmail@host.xxxxxx.com>
To: lyttmab@ppppp.com
Subject: I WISH TO HAVE YOU AS A PERSONAL ASSISTANT.
From: Mr.Morgan Kent <mr.morgankent2@ppppp.com>
Reply-To: morgankent202@ppppp.com
MIME-Version: 1.0
Content-Type: text/plain
Content-Transfer-Encoding: 8bit
morgankent2011@ppppp.com
mr.morgankent2011@ppppp.com
######OUTPUT TRUNCATED########

You can read the headers of the mails in the queue using the following command
[root@host ~]# /var/qmail/bin/qmail-qread
7 Dec 2011 14:22:43 GMT  #22708222  3232  <anonymous@host.xxxxxx.com>
        remote  crehkow@ppppp.com
7 Dec 2011 12:12:16 GMT  #22609322  3233  <anonymous@host.xxxxxx.com>
        remote  jbilodeau1@ppppp.com
7 Dec 2011 10:55:48 GMT  #14396666  3237  <anonymous@host.xxxxxx.com>
        remote  izzy46martinez@ppppp.com

For listing the mails in the mail queue with a particular content use the following command
[root@host ~]# qmail-remove -i -p "I WISH TO HAVE YOU AS A PERSONAL ASSISTANT"
It will list the mails with content I WISH TO HAVE YOU AS A PERSONAL ASSISTANT in it

The above command will only list the mails. for deleting them use option -r. Then all those mails will be moved to yanked directory.
[root@host ~]# qmail-remove -i -p "I WISH TO HAVE YOU AS A PERSONAL ASSISTANT"  -r
[root@host yanked]# pwd
/var/qmail/queue/yanked
[root@host yanked]# ls | wc -l
593379
[root@host yanked]#

Useful links
http://www.atomicorp.com/wiki/index.php/Spam
http://kb.parallels.com/en/1711
http://kb.parallels.com/en/766
http://www.linuxmagic.com/opensource/qmail/qmail-remove

No comments:

Post a Comment

Be nice. That's all.