Postfix 跟其他 MTA 一樣, 會將不能成功發送的郵件放到 Queue 裡面, 在特定的時間內重新嘗試發送, 超過指定的時間會自動刪除。但如果發送大量郵件, 例如有用戶發送大量垃圾電郵, 會在 Queue 內積壓大量的郵件, 這時可以手動刪除。
以下刪除 Postfix Queue 內郵件的方法:
列出 Postfix Queue 內所有郵件:
# mailq
刪除 Postfix Queue 內所有郵件:
# postsuper -d ALL
刪除所有 Deferred Queue 內的郵件:
# postsuper -d ALL deferred
以下 Perl Script 可以根據 regular expression 刪除郵件:
postfix-delete.pl
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
#!/usr/bin/perl $REGEXP = shift || die "no email-adress given (regexp-style, e.g. bl.*\@yahoo.com)!"; @data = qx</usr/sbin/postqueue -p>; for (@data) { if (/^(\w+)(\*|\!)?\s/) { $queue_id = $1; } if($queue_id) { if (/$REGEXP/i) { $Q{$queue_id} = 1; $queue_id = ""; } } } #open(POSTSUPER,"|cat") || die "couldn't open postsuper" ; open(POSTSUPER,"|postsuper -d -") || die "couldn't open postsuper" ; foreach (keys %Q) { print POSTSUPER "$_\n"; }; close(POSTSUPER); |
例如要刪除所有在 Queue 內網域是 spam.domain 的郵件, 可以這樣:
# ./postfix-delete.pl spam.domain
学习了