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
学习了