使用sendmail,您将如何将所有外发邮件发送到/ dev / null或者防止邮件被排队或发送?
在开发nagios框我想阻止发送邮件,以便通知不会出去。 停止出站邮件将允许我按原样testingnagiosconfiguration并防止虚假通知。
我通过完全禁用sendmail,然后让一个简单的perl脚本在SMTP端口上侦听,并将这些电子邮件转储到一个目录中,从而在我的开发框中完成了这项工作。 我确信可以使用sendmailconfiguration,但是perl脚本要容易得多。 这里是精简到要点:
#!/usr/bin/perl -w use Net::SMTP::Server; use Net::SMTP::Server::Client; $server = new Net::SMTP::Server || die("$!\n"); while($conn = $server->accept()) { my $client = new Net::SMTP::Server::Client($conn) || die("Unable to handle client connection: $!\n"); $client->process || next; # Here's where you can write it out or just dump it. Set $filename to # where you want to write it open(MAIL,"> $filename") || die "$filename: $1"; print(MAIL "$client->{MSG}\n"); close(MAIL); }
以下将所有内容发送到/ dev / null:
LOCAL_RULE_0 R$* < @ $* > $* $#local $: bit-bucket
这假定在你的/ etc / aliases中:
bit-bucket: /dev/null