Skip to content

Postsuper: Mass Deletion of Emails in the Queue

Introduction

Postsuper is a Postfix utility that allows you to delete emails in the queue. I needed it to delete around 40,000 emails that were error messages from the MAILER-DAEMON user, with approximately 300 emails in the batch that needed to be delivered.

Complete Deletion

To delete all emails in the queue:

postsuper -d ALL

Partial Deletion

To delete all emails from the MAILER-DAEMON user, here's the script (replace MAILER-DAEMON with another name if needed):

1
2
3
4
5
6
#!/bin/sh
supp=`mailq | grep MAILER-DAEMON | awk -F"*" '{ print $1 }'`

for i in $supp ; do
        postsuper -d $i  
done

Or alternatively, here's another example:

mailq | tail +2 | awk 'BEGIN { RS = "" } / user@mydomain\.com$/ { print $1 }' | tr -d '*!' | postsuper -d -