Author Topic: Empty Postfix Mail Queue  (Read 7317 times)

Offline admin

  • Administrator
  • Sr. Member
  • *****
  • Posts: 296
    • View Profile
Empty Postfix Mail Queue
« on: January 25, 2012, 03:16:33 PM »
Empty Postfix Mail Queue

This command will delete one specific email from the mailq (taken from the postsuper man page)
Code: [Select]
mailq | tail -n +2 | grep -v '^ *(' | awk  'BEGIN { RS = "" } { if ($8 == "email@address.com" && $9 == "") print $1 } ' | tr -d '*!' | postsuper -d -
I use a few scripts that check the status of our servers and email/page me if they don't respond. This led to a problem when I was offline for one reason or another. I would get a ton of messages sent to the postfix queue which would all be sent out when I reconnected to the internet. Deleting the postfix mail Queue is suprisingly easy:
Code: [Select]
sudo postsuper -d ALL

This command will delete all messages in the Postfix queue. If you need more selective deleting, this can be done as well, use 'man postsuper' to find out all of the available options.


The other thing that helped with this was checking for a local network connection before doing the server checks. This is done with the following.
Code: [Select]
ifconfig | grep netmask | grep -v 127.0.0.1 | awk {'print $2'}L