最近管理邮件系统时发现几个问题,一个是有些用户设置了转发,但是转发地址有问题,经常因为退信而塞爆 邮箱(有邮箱限额),之后的邮件都会被塞到等待队列里。还有就是有许多寄到本地虚拟域的信没有对应的用户,按说 Postfix 应该不会投递这类邮件,但是实际情况是它交给 maildrop 投递,而 maildrop 发现没有该用户,报告指定用户非法,这时正确的动作应该是退信,不过可能是我用的版本太低,maildrop 没有退信,而是把它放到等待队列里等待下次再试。这样等待队列里经常会有大量的这种邮件。所以,要想办法把这些邮件都清除掉。
在《Postfix 权威指南》里有一个叫 pfdel 的 Perl 小程序,可以用它删除指定邮件地址的邮件(不管是发信人还是收信人的邮件地址),这个虽然方便,但是如果想要清除因为 maildir over quota 或者 InvalID user specifIEd 错误而产生的邮件,还需要修改一下。下面是这四个程序:
pfdel.pl luserdel.pl moqdel.pl jmoqdel.pl
其中,pfdel.pl 是用来删除队列中指定用户的邮件的,luserdel.pl 是用来删除队列中无效用户的邮件的,moqdel.pl 是用来删除队列中邮箱配额已满的用户的邮件的,jmoqdel.pl 是删除邮箱配额已满的用户的垃圾邮件箱的。
pfdel.pl
#!/usr/bin/perl -w#
# pfdel - deletes message containing specifIEd address from
# Postfix queue. Matches either sender or recipIEnt address.
#
# Usage: pfdel <email_address>
#
use strict;
# Change these paths if necessary.
my $ListQ = "/usr/sbin/postqueue -p";
my $postsUPER = "/usr/sbin/postsuper";
my $email_addr = "";
my $qID = "";
my $euID = $>;
if ( @ARGV != 1 ) {
dIE "Usage: pfdel <email_address>\n";
} else {
$email_addr = $ARGV[0];
}
if ( $euID != 0 ) {
dIE "You must be root to delete queue files.\n";
}
open(QUEUE,"$ListQ |") ||
dIE "Can't get pipe to $ListQ: $!\n";
my $entry = <QUEUE>; # skip single header line
$/ = ""; # Rest of queue entrIEs print on
# multiple lines.
while ( $entry = <QUEUE> ) {
if ( $entry =~ / $email_addr$/m ) {
($qID) = split(/\s+/,$entry,2);
$qID =~ s/[\*\!]//;
next unless ($qID);
#
# Execute postsuper -d with the queue ID.
# postsuper provIDes Feedback when it deletes
# messages. Let its output go through.
#
if ( system($postsUPER,"-d",$qID) != 0 ) {
# If postsuper has a problem,bail.
dIE "Error executing $postsUPER: error " .
"code " . ($?/256) . "\n";
}
}
}
close(QUEUE);
if (! $qID ) {
dIE "No messages with the address <$email_addr> " .
"found in queue.\n";
}
luserdel.pl
#!/usr/bin/perl -w
#
# luserdel - deletes message containing invalID user from
# Postfix queue.
#
# Usage: luserdel
#
use strict;
# Change these paths if necessary.
my $ListQ = "/usr/sbin/postqueue -p";
my $postsUPER = "/usr/sbin/postsuper";
my $qID = "";
my $euID = $>;
if ( $euID != 0 ) {
dIE "You must be root to delete queue files.\n";
}
open(QUEUE,"$ListQ |") ||
dIE "Can't get pipe to $ListQ: $!\n";
my $entry = <QUEUE>; # skip single header line
$/ = ""; # Rest of queue entrIEs print on
# multiple lines.
while ( $entry = <QUEUE> ) {
if ( $entry =~ /InvalID user specifIEd/m ) {
($qID) = split(/\s+/,2);
$qID =~ s/[\*\!]//;
next unless ($qID);
#
# Execute postsuper -d with the queue ID.
# postsuper provIDes Feedback when it deletes
# messages. Let its output go through.
#
if ( system($postsUPER,$qID) != 0 ) {
# If postsuper has a problem,bail.
dIE "Error executing $postsUPER: error " .
"code " . ($?/256) . "\n";
}
}
}
close(QUEUE);
if (! $qID ) {
dIE "No invalID user messages found in queue.\n";
}
exit 0;
#
# moqdel - deletes message containing maildir over quota from
# Postfix queue.
#
# Usage: moqdel
#
use strict;
# Change these paths if necessary.
my $ListQ = "/usr/sbin/postqueue -p";
my $postsUPER = "/usr/sbin/postsuper";
my $qID = "";
my $euID = $>;
if ( $euID != 0 ) {
dIE "You must be root to delete queue files.\n";
}
open(QUEUE,"$ListQ |") ||
dIE "Can't get pipe to $ListQ: $!\n";
my $entry = <QUEUE>; # skip single header line
$/ = ""; # Rest of queue entrIEs print on
# multiple lines.
while ( $entry = <QUEUE> ) {
if ( $entry =~ /maildir over quota/m ) {
($qID) = split(/\s+/,bail.
dIE "Error executing $postsUPER: error " .
"code " . ($?/256) . "\n";
}
}
}
close(QUEUE);
if (! $qID ) {
dIE "No maildir over quota messages found in queue.\n";
}
exit 0;
jmoqdel.pl
#!/usr/bin/perl -w # # jmoqdel - deletes Junk directorIEs whose maildir over quota from # Postfix queue. # # Usage: jmoqdel # use strict; my $HOME_BASE = "/home/vmail"; # Change these paths if necessary. my $ListQ = "/usr/sbin/postqueue -p"; my $postsUPER = "/usr/sbin/postsuper"; my $user = ""; my $domain = ""; my $email = ""; my $euID = $>; if ( $euID != 0 ) { dIE "You must be root to delete queue files.\n"; } open(QUEUE,"$ListQ |") || dIE "Can't get pipe to $ListQ: $!\n"; my $entry = <QUEUE>; # skip single header line $/ = ""; # Rest of queue entrIEs print on # multiple lines. while ( $entry = <QUEUE> ) { if ( $entry =~ /maildir over quota/m ) { ($user,$domain,$email) = split(/\n/,3); ($user,$domain) = ($email =~ m!\s*(.+)@(.+)\s*!); `rm $HOME_BASE/$domain/$user/Maildir/.Junk -rf &> /dev/null`; next unless ($email); } } close(QUEUE); if (! $email ) { dIE "No maildir over quota messages found in queue.\n"; }
总结以上是内存溢出为你收集整理的postfix邮件队列管理全部内容,希望文章能够帮你解决postfix邮件队列管理所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)