Linux – Remove messages from sendmail queue matching subject

centoslinuxsendmail

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.

Best Answer

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.

cd /var/spool/mqueue
for file in `grep "Subject:.*litigate gasworks" *|cut -f 1 -d:|cut -c2-`; do echo *${file} ; done

Once you're happy with the list of files it produces, change echo to rm. Don't forget to stop sendmail before you mess with its queue like this; it may become surly if the queue changes underneath it.