我如何配置 postfix 以便所有来自 php mail 的电子邮件也将被 spamassassin 扫描?

我如何配置 postfix 以便所有来自 php mail 的电子邮件也将被 spamassassin 扫描?

我看到很多关于如何从网络中的某个 IP 地址或通过提交等方式在 Postfix 中扫描邮件的文章。但我认为 php mail 使用 sendmail 并在本地注入邮件。

什么样的配置可以让我成功确保从服务器的 PHP 邮件发送的所有电子邮件也收到相同的垃圾邮件扫描处理?

我的 /etc/postfix/master.cf

smtp      inet  n       -       y       -       -       smtpd
  -o content_filter=spamassassin
submission inet n       -       y       -       -       smtpd
  -o syslog_name=postfix/submission
  -o smtpd_tls_security_level=encrypt
  -o smtpd_sasl_auth_enable=yes
  -o smtpd_tls_auth_only=yes
  -o smtpd_client_restrictions=permit_sasl_authenticated,reject
smtps     inet  n       -       y       -       -       smtpd
  -o content_filter=spamassassin
pickup    unix  n       -       y       60      1       pickup
cleanup   unix  n       -       y       -       0       cleanup
qmgr      unix  n       -       n       300     1       qmgr
tlsmgr    unix  -       -       y       1000?   1       tlsmgr
rewrite   unix  -       -       y       -       -       trivial-rewrite
bounce    unix  -       -       y       -       0       bounce
defer     unix  -       -       y       -       0       bounce
trace     unix  -       -       y       -       0       bounce
verify    unix  -       -       y       -       1       verify
flush     unix  n       -       y       1000?   0       flush
proxymap  unix  -       -       n       -       -       proxymap
proxywrite unix -       -       n       -       1       proxymap
smtp      unix  -       -       y       -       -       smtp
relay     unix  -       -       y       -       -       smtp
        -o syslog_name=postfix/$service_name
showq     unix  n       -       y       -       -       showq
error     unix  -       -       y       -       -       error
retry     unix  -       -       y       -       -       error
discard   unix  -       -       y       -       -       discard
local     unix  -       n       n       -       -       local
virtual   unix  -       n       n       -       -       virtual
lmtp      unix  -       -       y       -       -       lmtp
anvil     unix  -       -       y       -       1       anvil
scache    unix  -       -       y       -       1       scache
maildrop  unix  -       n       n       -       -       pipe
  flags=DRhu user=vmail argv=/usr/bin/maildrop -d ${recipient}
uucp      unix  -       n       n       -       -       pipe
  flags=Fqhu user=uucp argv=uux -r -n -z -a$sender - $nexthop!rmail ($recipient)
ifmail    unix  -       n       n       -       -       pipe
  flags=F user=ftn argv=/usr/lib/ifmail/ifmail -r $nexthop ($recipient)
bsmtp     unix  -       n       n       -       -       pipe
  flags=Fq. user=bsmtp argv=/usr/lib/bsmtp/bsmtp -t$nexthop -f$sender $recipient
scalemail-backend unix  -       n       n       -       2       pipe
  flags=R user=scalemail argv=/usr/lib/scalemail/bin/scalemail-store ${nexthop} ${user} ${extension}
mailman   unix  -       n       n       -       -       pipe
  flags=FR user=list argv=/usr/lib/mailman/bin/postfix-to-mailman.py
  ${nexthop} ${user}

spamassassin unix -     n       n       -       -       pipe
  user=spamd argv=/usr/bin/spamc -f -e  
  /usr/sbin/sendmail -oi -f ${sender} ${recipient}

答案1

我在网上找到了一个可以帮我完成这个任务的脚本。我稍微调整了一下。不确定这是否是最好的方法,但确实有效。

为了安装它我修改了/etc/php/7.2/apache2/php.ini并修改了以下行以表明:

; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
; http://php.net/sendmail-path
sendmail_path = /usr/local/bin/php-mail-filter.pl

脚本位于/usr/local/bin/php-mail-filter.pl

#!/usr/bin/perl
use Mail::SpamAssassin::Client;

my $client = new Mail::SpamAssassin::Client({ port => 783, host => 'localhost' });

my $testmsg = join( "", <STDIN> );
#my $testmsg = '';
# PHP sends MIME over STDIN
#while (my $line = ) {
#   $testmsg .= $line;
#}

# process message over SPAMASSASSIN
my $result = $client->process($testmsg);

#print "Result $result->{isspam}";

if ($result->{isspam} eq 'False') {
   # not spam - open pipe to sendmail and send it
   open(MAIL,"|/usr/sbin/sendmail -t -i");
   print MAIL $testmsg;
   close(MAIL);
   exit 1;
} else {
   # spam - do nothing
   exit -1;
}

希望这能对某些人有所帮助,并节省他们在网上搜索的 15 分钟时间。

来源:http://blog.mine.sk/force-outgoing-mails-from-php-mail-function-through-spamassassin.html

相关内容