Deleting Spam mails in qmail

Qmail is one of the famous open source email servers like postfix,
sendemail, exim etc.

Today, got a qmail server which was very slow in sending emails.
It took even 24 hours to send an email.

Let us see here, how to solve this issue.

Spam mails are the major reason on slowness of any email server.

First we have to check the email queue to know how many mails are
there to be processed.

# /var/qmail/bin/qmail-qstat
messages in queue: 23645
messages in queue but not yet preprocessed: 82

ooops.
23645 mails in the queue is a huge number.

The next step is to use is “qmail-qread”, which can be used to read

the message headers:

# /var/qmail/bin/qmail-qread
18 Jul 2005 15:03:07 GMT #2996948 9073 <user> bouncing

done remote user1
done remote user2
done remote user3

23 Feb 2013 22:52:24 GMT #13633871 2239 <ef6276> bouncing

remote cnsccorp
done remote cnsccorp
done remote cnsccorp

done remote cnsccorp
remote cnsccorp
remote cnscenic

….

I see here that there are many emails from the email address ef6276
where all the mails contain bogus TO address.

So, all these mails are SPAM mails and can be deleted.

Let us count how many spam mails are there.

qmHandle is a nice tool to handle the email queue in the qmail.

using this, we can list the queue, send all the mails in the queue,
delete the mails using any field like sender, receiver, domain,

subject, body text even using regular expression.

options for qmandle

-l to list the queue
-s to summarize the queue
-a to send all emails
-fsender to delete emails from sender

/usr/local/src/qmhandle-1.3.2/qmHandle -l | grep From | grep ef6276 | wc -l
22735

So, there are 22735 spam mails that are generated from single email
address ef6276

Let us delete them all.

/usr/local/src/qmhandle-1.3.2/qmHandle -fef6276

It took some 30 min to delete all the spam emails.

Let us check the queue status now.

/usr/local/src/qmhandle-1.3.2/qmHandle -s

Total messages: 910
Messages with local recipients: 0
Messages with remote recipients: 910
Messages with bounces: 10
Messages in preprocess: 0

So, there are 910 valid emails

Let us try to send them all.

/usr/local/src/qmhandle-1.3.2/qmHandle -a

That’s all.

In some 30 minutes, all the valid emails are sent and the email server
started to breath easily.

Thanks to the following links which helped me to know about qmail.

http://blog.xfloyd.net/?p=109

http://pc-freak.net/blog/how-to-fix-a-broken-qmail-queue-with-queue-repair-and-qmhandle/

http://linuxhostingsupport.net/blog/howto-manage-mail-queue-in-qmail-using-qmhandle

http://lateral.netmanagers.com.ar/stories/8.html

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s