As a website design and development agency, we are inextricably tied to the world of servers, email and the bane of everyone’s existence, SPAM (no, not the canned meat – you know the one). Whilst many websites operate on shared hosting systems, and the wildly popular cPanel platform, we’re seeing a growing number of dedicated or virtual servers in operation. Maybe you, like me, thought self-hosted email solutions were a dying technology with Gmail and Office 365 being available ubiquitously. But no – old, physical machines are being virtualised and we’re seeing a surprising number of older systems standing the test of time. Take Qmail for example, a Mail Transfer Agent (MTA) designed to replace sendmail back in 1995. We have happened across a few environments where Qmail is in use because “it’s simple and just works”. We can’t argue with that, but if you’ve ever found yourself navigating SPAM and Qmail, you may have come across an issue where some messages aren’t being delivered.
If you’re running a Qmail mail server that’s been hit by some SPAM, chances are it’s just sitting in the queue. You could just clear the entire queue, but to be safe (if there is some consistency to the SPAM. I.e. the same recipient or sender address), then you can run a filtered deletion command using qmHandle. The package isn’t installed by default, so follow the steps below to download and use qmHandle:
- Login onto the mail server and download the qmHandle package using the link below:-cd /usr/local/src/
[EDIT: I actually hit a certificate error the second time I ran this (on a different server). I was able to proceed by appending the “–no-check-certificate” parameter.]
- Extract the qmHandle binary using the command below:-tar -xzf download OR qmhandle-1.3.2.tar.gz
- Move the Qmail binary from its directory to the Qmail binary directory where you’ve installed it on the server. For example if you installed it under /var/qmail/ follow the steps below:cd qmhandle-*/
mv qmHandle /var/qmail/bin/
- Now that qmHandle is set up, we’ll use it to check for message from a certain sender, and delete these messages:/var/qmail/bin/qmHandle -l | grep From | grep FROM_ADDRESS
- [EDIT: On my second run I had to vi the qmHandle script to change the stopqmail and startqmail variables. I left stopqmail blank, and set startqmail to the <1.03 version setting.]
- qmailctl start
Here are a list of other commands for qmHandle:
# Forcefully send emails.
# List message queues
# delete all messages in the queue
# list local message queue
# list remote message queue
# display message number N
# delete message number N
# delete all messages that contain text as Subject
# delete all messages that contain text as From email address
# delete all messages that contain text as To email address
In 2020, there are a seemingly unlimited number of server + email server combinations. If you’re dealing with a Linux/Unix environment running Qmail to handle mail, then hopefully you can now deal with this pesky little issue!