最近管理邮件系统时发现几个问题,一个是有些用户设置了转发,但是转发地址有问题,经常因为退信而塞爆 邮箱(有邮箱限额),之后的邮件都会被塞到等待队列里。还有就是有许多寄到本地虚拟域的信没有对应的用户,按说 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. Surf Gym - 100819S
  3. 数据结构栈队列链表数组
  4. easyui treegrid获取父节点的id_超简单的分布式ID生成方案!美团开源框架介绍
  5. linux 0.11 内核学习 -- rs_io.s,串口汇编代码
  6. 算法录 之 复杂度分析。
  7. node中操作MySQL
  8. div css网页设计源代码_HTML+CSS网页设计,企业网站服务项目布局样式
  9. Jquery取得iframe中元素的几种方法(转载)
  10. 抽象工厂模式_设计模式(3) 抽象工厂模式
  11. VisualGDB系列8:使用VS创建CMake Linux项目
  12. gc日志怎么看_JVM探秘:GC日志收集与分析
  13. [易飞]关于应付账款明细帐余额余总账不平解决方案
  14. refresh( )
  15. hive插入多条数据sql_HIVE sql使用总结
  16. 百度云直链下载-IDM+网页解析(三)
  17. markdown中修改图片大小
  18. 研发管理进阶:边怼人边改进
  19. 项目管理软件,协同管理软件介绍
  20. 支付宝手机网页唤醒app支付

热门文章

  1. 思科修复运营商级路由器中的两个已遭利用漏洞
  2. Elasticsearch 架构原理—— 新数据写入过程
  3. csharp:Convert Image to Base64 String and Base64 String to Image
  4. Jmeter分布式测试-远程调用
  5. 1.8 centos7网络排错
  6. 手把手教你解密MacOS平台下的Chrome密码
  7. robotframework的学习笔记(十六)----robotframework标准库String
  8. 一文带你了解目前的“光伏母亲公路” 能照明充电和融雪
  9. 报错A Database Error Occurred,linux系统被cc***
  10. android 原生 电子邮件 应用 发送邮件附带 中文名附件时 附件名称乱码问题解决...