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

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: 37645
messages in queue but not yet preprocessed: 68
37645 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:
To find out the userid sending most no spam messages
#/var/qmail/bin/qmail-qread > file
#sed -e ‘s/\s/\n/g’ < file | sort | uniq -c | sort -nr | head -30
(or) just try list of spam messages send by userid
# /var/qmail/bin/qmail-qread
18 Jul 20013 15:03:07 GMT #2996948 9073 <dfsja6> bouncing

done sathish.com sathish
done sam.com sam
done jane.com jane


I see here that there are many emails from the email address dfsja6
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

for installing qmHandle, follow by previous post https://sathisharthars.wordpress.com/2013/11/07/configuring-qmail-server-with-smtpssl-along-with-spamassassin-clamav-simscan-and-squirrelmail-vpopmail-and-dovecot/

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

So, there are 37645 spam mails that are generated from single email

Let us delete them all.

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

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