Qmail - Check and Delete Spam mails from the Server


Plesk control panel uses qmail as a mail server. Following are some of the qmail commands for Plesk server.

# /var/qmail/bin/qmail-qstat
   To check the mail queue in plesk from command line.

# /var/qmail/bin/qmail-qread
   To examine the queue with qmail-qread.

From the qmail-qread command you get the message’s id, a number followed by '#' symbol. Let one of the id is '1234' . Now you can find the file holding the email in /var/qmail/queue with “find “command.

# find /var/qmail/queue -iname 1234

   The find result will be like the following..,
   /var/qmail/queue/remote/22/1234
   /var/qmail/queue/mess/22/1234
   /var/qmail/queue/info/22/1234


From the mail header you get the IP address, the following command will display the mail header of  1234.

# cat /var/qmail/queue/mess/22/1234

You can analyse the To, From and Subject to determine whether an email is spam or not. The site given below contains the normal spamming content in e-mails. But spamming contents are changed day by day. Mostly they are sales or adds related.
http://spamspamgoaway.com/spam-subjects.php


Issue the following command and analyse the result to find the spam.

# egrep -ir "(Subject|To|From)" /var/qmail/queue/mess/

You can find a large number of particular pattern in the command result which caused spam. Let the content be like this "Start earning 15 minutes from now". You can delete all the spam mails containing the above content by issuing the fillowing command
# /usr/local/script/qmqtool -d -f "Start earning 15 minutes from now"

After that verify the spamming mails were removed or not by checking the result of,
# egrep -ir "(Subject|To|From)" /var/qmail/queue/mess/


Note:- If qmqtool is not in your server, you should install it. The following link will help you to install qmqtool.
http://linuxadmintips4u.blogspot.in/2012/08/qmail-install-and-compile-qmqtool.html


This entry was posted in by Arun Ghosh. Bookmark the permalink.