Script Perl para Apagar Fila Postfix

Traditionally you use the “sendmail -q” command to flush mail queue under Sendmail MTA. Under Postfix MTA, just enter the following command to flush the mail queue:
# postfix flush
OR
# postfix -f

To see mail queue, enter:
# mailq

To remove all mail from the queue, enter:
# postsuper -d ALL

To remove all mails in the deferred queue, enter:
# postsuper -d ALL deferred

postfix-delete.pl script

Following script deletes all mail from the mailq which matches the regular expression specified as the first argument (Credit: ??? – I found it on old good newsgroup)

  1. #!/usr/bin/perl
  2. $REGEXP = shift || die “no email-adress given (regexp-style, e.g. bl.*\@yahoo.com)!”;
  3. @data = qx</usr/sbin/postqueue -p>;
  4. for (@data) {
  5. if (/^(\w+)(\*|\!)?\s/) {
  6. $queue_id = $1;
  7. }
  8. if($queue_id) {
  9. if (/$REGEXP/i) {
  10. $Q{$queue_id} = 1;
  11. $queue_id = “”;
  12. }
  13. }
  14. }
  15. #open(POSTSUPER,”|cat”) || die “couldn’t open postsuper” ;
  16. open(POSTSUPER,”|postsuper -d -“) || die “couldn’t open postsuper” ;
  17. foreach (keys %Q) {
  18. print POSTSUPER “$_\n”;
  19. };
  20. close(POSTSUPER);

For example, delete all queued messages from or to the domain called fackspamdomain.com, enter:
./postfix-delete.pl fackspamdomain.com
Delete all queued messages that contain the word “xyz” in the e-mail address:
./postfix-delete.pl xyz

Updated for accuracy.

Créditos : http://www.cyberciti.biz/tips/howto-postfix-flush-mail-queue.html

Deixe um comentário

O seu endereço de e-mail não será publicado. Campos obrigatórios são marcados com *