最近管理邮件系统时发现几个问题,一个是有些用户设置了转发,但是转发地址有问题,经常因为退信而塞爆 邮箱(有邮箱限额),之后的邮件都会被塞到等待队列里。还有就是有许多寄到本地虚拟域的信没有对应的用户,按说 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+/, $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 invalid user messages found in queue.\n";
}
 
exit 0;

moqdel.pl
#!/usr/bin/perl -w
#
# 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+/, $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 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/, $entry, 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";
}

转载于:https://blog.51cto.com/zhangbo1119/948809

postfix邮件队列管理相关推荐

  1. linux 卸载postfix,Postfix 邮件队列删除

    Postfix中有一套Mail Queue Management(邮件队列管理)机制,所有队列中的邮件都可以全自动的处理,但在发送大量邮件的时候,有必要对这个队列进行手工的维护处理,比如说,删除队列中 ...

  2. Postfix邮件队列查看方法

    PostFix之postqueue指令 看被Queue的信: postqueue -p  or mailq 強迫将Queue信寄出: postqueue -f 刪除所有被Queue的信: postsu ...

  3. Linux网络服务与shell脚本——Postfix邮件服务器搭建

    Postfix邮件系统 1.电子邮件系统基础 (1)邮件系统角色.邮件协议 ①邮件系统的角色 1)MTA(Mail Transfer Agent,邮件传输代理):邮件服务器软件 2)MUA(Mail ...

  4. Asp.Net Core 快速邮件队列设计与实现

    发送邮件几乎是软件系统中必不可少的功能,在Asp.Net Core 中我们可以使用MailKit发送邮件,MailKit发送邮件比较简单,网上有许多可以参考的文章,但是应该注意附件名长度,和附件名不能 ...

  5. postfix管理邮件队列的小程序

    邮件服务器中的队列有许多是垃圾邮件的退信,以往清理的时候就会把所有队列中的邮件全部清除掉,这样会把一些正常邮件也清除. 在<Postfix 权威指南>里有一个叫 pfdel 的 Perl ...

  6. Exchange系列—管理邮件队列

    集线器传输服务器在从用户邮箱接收邮件后或者是边缘传输服务器从集线器传输服务器端接收到邮件后,由pickup directory组件将邮件提交到提交队列,提交队列组件在邮件被处理之前将邮件存储到硬盘上, ...

  7. postfix邮件管理

    *************实验前配置环境***************** ***首先重置两台虚拟机*** ####desktop主机##### vim /etc/sysconfig/network- ...

  8. postfix邮件安装配置文档

    POSTFIX邮局系统搭建全过程 第一篇:邮件系统搭建 一.系统环境: 1. 采用Centos 5.5系统也或者是rhel 5.5: 2. 内存最好为512M以上: 3. 本次采用的系统主机名为mai ...

  9. Linux中Postfix邮件发送配置(三)

    部署DNS服务器 postfix根据域名和地址做一个MX记录,A记录,PTR记录(一般在互联网上邮件服务器都要反解,没有PTR记录会认为是垃圾邮件) $ service iptables stop $ ...

最新文章

  1. 女神推荐, 卡片,广告图 ,点击查看更多
  2. 数据通信技术_华为数据通信创新峰会在长春圆满举行
  3. 浅谈MySQL的七种锁
  4. 得到按钮句柄后如何点集_RepPoint:可形变卷积生成的目标轮廓点集
  5. java 名词解释等
  6. 不止有超大杯!小米10系列还将新增配色
  7. 维特比算法一点个人理解
  8. 注意力机制介绍(attention)
  9. MeasureSpec介绍及使用详解
  10. oracle 字段名中有空格 的查询
  11. android 微信浮窗实现_Android仿微信文章悬浮窗效果的实现代码
  12. windbg命令解释
  13. 达梦数据库在ZYJ环境上进行服务的配置
  14. 龙的战争 Dragon ‘s War
  15. Qemu core 调试Cannot access memory at address 0x7fbc6c792858
  16. Crack:Aspose.Slides for .NET 22.12.x
  17. @Inject与@Injectable
  18. 最安全的邮箱-Gmail
  19. Unity开发元宇宙多人交互XR应用
  20. AD学习笔记(四)PCB布局分析

热门文章

  1. 数百款惠普打印机易受严重RCE漏洞影响
  2. 无人机在高楼区做倾斜摄影的地籍建模的项目报告
  3. Linux x86主机运行天数是是24.8的倍数都有可能引发oracle bug及解决方法
  4. JavaScript 函数replace揭秘
  5. linux echo设置颜色
  6. KVM virtio bug整理
  7. 【Vegas原创】SQL Server 2005部署备份任务
  8. 让系统自动登录的方法
  9. Nokia Booklet 3G试用小记
  10. [Java] 蓝桥杯ALGO-13 算法训练 拦截导弹