Postifx: delete mails in queue from a specific domain (or TLD)

Quick tip for managing postfix’s mail queues. A customer uses an old mailing software and he got subscription of unknown domains, which then remains in queue for long time. To purge a single domain from your mail queue use the following command:

mailq | grep -B3 "\.ovh$" | grep "^[0-9A-Z]" | cut -f 1 -d ' ' | xargs -n 1 postsuper -d

this will delete all mails in queue for the TLD .ovh.

  • mailq shows the mail queue;
  • grep is used to pick the lines for our selected domain. The -B3 options means to also show three lines before the matched one;
  • grep once more is to select only the rows starting with a postfix queue ID;
  • cut is to pick only the first word of the line, which is the postfix queue ID. We could have used awk {print $1} as well;
  • xargs is to run a command against a list of elements;
  • postsuper -d is for finally deleting an element from the postfix queue.


Articoli recenti

Commenti recenti



maxxer Written by:

Be First to Comment

Lascia un commento

Il tuo indirizzo email non sarà pubblicato. I campi obbligatori sono contrassegnati *