I'm running centos and have a rediculous amount of emails in the mailqueue due to a script error. Is there any way to remove messages that have a certain subject line in sendmail's mailqueue.
I'm running centos and have a rediculous amount of emails in the mailqueue due to a script error. Is there any way to remove messages that have a certain subject line in sendmail's mailqueue.
This worked for me just now, in testing (which is why it has such a weird subject line embedded in the code). It relies on the fact that the two files that make up a message in sendmail queue share the same filename except for the first character.
Once you're happy with the list of files it produces, change
echo
torm
. Don't forget to stop sendmail before you mess with its queue like this; it may become surly if the queue changes underneath it.In the sendmail
contrib/
directory there's a perl scriptqtool.pl
that lets you safely make interventions on spool directories while sendmail is running. You can delete, bounce, move, and filter by age, size, sender, recipient and subject (amongst other things).Inexplicably, it is not included with the main CentOS sendmail package, you can find it in the sendmail-doc rpm though (thanks to kubanczyk for noting this), or you can extract it from the source distribution ( ftp://ftp.sendmail.org/pub/sendmail/sendmail-current.tar.gz ). It has minimal dependencies, they should all be part of a normal perl installation.
To delete messages use
-d
:To move them to an offline mqueue directory (safer):
Note it's "
qtool.pl destination/ source/
". Locked files (those with a "*" by the queue ID inmailq
output) will not be moved, you may need to retry to catch those.You have the option of running that queue later with
sendmail -qR [...] -O QueueDirectory=/var/spool/mqueue-junk
.(Older versions of
qtool.pl
are known to not parse the headers correctly, you need to omit the first letter on most headers, e.g.$msg{headers}->{ubject}
instead of{Subject}
)