我在我的机器(linux)上使用 Postfix。
当我向本地用户发送邮件时telnet 本地主机 25在命令行中,我的邮件由内容过滤器(例如:spamassassin)解析 => 没有问题。
但是当我向同一个本地用户发送邮件时邮件命令(或 sendmail 命令或 mail php),我的邮件已发送但未被内容过滤器解析 => 那么为什么呢?
为什么当我使用邮件命令时我的邮件不被内容过滤器解析?
我的 Postfix 配置非常简单:
后配置-n:
alias_database = hash:/etc/aliases
alias_maps = hash:/etc/aliases
append_dot_mydomain = no
biff = no
config_directory = /etc/postfix
html_directory = /usr/share/doc/postfix/html
inet_interfaces = all
mailbox_size_limit = 0
mydestination = localhost.localdomain, localhost, localhost.localdomain, localhost
myhostname = localhost
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
myorigin = /etc/mailname
recipient_delimiter = +
relayhost =
smtpd_banner = $myhostname ESMTP $mail_name (Debian/GNU)
后配置-M:
smtp inet n - n - - smtpd -o content_filter=spamassassin
pickup fifo n - - 60 1 pickup
cleanup unix n - - - 0 cleanup
qmgr fifo n - n 300 1 qmgr
tlsmgr unix - - - 1000? 1 tlsmgr
rewrite unix - - - - - trivial-rewrite
bounce unix - - - - 0 bounce
defer unix - - - - 0 bounce
trace unix - - - - 0 bounce
verify unix - - - - 1 verify
flush unix n - - 1000? 0 flush
proxymap unix - - n - - proxymap
proxywrite unix - - n - 1 proxymap
smtp unix - - - - - smtp
relay unix - - - - - smtp
showq unix n - - - - showq
error unix - - - - - error
retry unix - - - - - error
discard unix - - - - - discard
local unix - n n - - local
virtual unix - n n - - virtual
lmtp unix - - - - - lmtp
anvil unix - - - - 1 anvil
scache unix - - - - 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=mail argv=/usr/bin/spamc -u ${user} -e /usr/sbin/sendmail -oi -f ${sender} ${recipient}
我重复一下我的问题:当我使用 telnet localhost 25 向本地用户(访客)发送邮件时,spamassassin 解析该邮件,并且 syslog 显示:
Feb 4 15:05:42 localhost postfix/smtpd[3919]: connect from localhost[::1]
Feb 4 15:05:50 localhost postfix/smtpd[3919]: EBC2460DBF: client=localhost[::1]
Feb 4 15:05:59 localhost postfix/cleanup[3922]: EBC2460DBF: message-id=<20150204140550.EBC2460DBF@localhost>
Feb 4 15:05:59 localhost postfix/qmgr[3883]: EBC2460DBF: from=<[email protected]>, size=342, nrcpt=1 (queue active)
Feb 4 15:05:59 localhost spamd[18634]: spamd: connection from localhost [127.0.0.1] at port 48540
Feb 4 15:05:59 localhost spamd[18634]: spamd: processing message <20150204140550.EBC2460DBF@localhost> for guest:122
Feb 4 15:06:08 localhost spamd[18634]: spamd: clean message (0.2/5.0) for guest:122 in 9.1 seconds, 296 bytes.
Feb 4 15:06:08 localhost spamd[18634]: spamd: result: . 0 - ALL_TRUSTED,MISSING_HEADERS scantime=9.1,size=296,user=guest,uid=122,required_score=5.0,rhost=localhost,raddr=127.0.0.1,rport=48540,mid=<20150204140550.EBC2460DBF@localhost>,autolearn=ham
Feb 4 15:06:08 localhost spamd[18632]: prefork: child states: II
Feb 4 15:06:08 localhost postfix/pickup[3881]: 6844560FDB: uid=8 from=<[email protected]>
Feb 4 15:06:08 localhost postfix/pipe[3923]: EBC2460DBF: to=<[email protected]>, orig_to=<guest>, relay=spamassassin, delay=22, delays=12/0.01/0/9.2, dsn=2.0.0, status=sent (delivered via spamassassin service)
Feb 4 15:06:08 localhost postfix/qmgr[3883]: EBC2460DBF: removed
Feb 4 15:06:08 localhost postfix/cleanup[3922]: 6844560FDB: message-id=<20150204140550.EBC2460DBF@localhost>
Feb 4 15:06:08 localhost postfix/qmgr[3883]: 6844560FDB: from=<[email protected]>, size=656, nrcpt=1 (queue active)
Feb 4 15:06:08 localhost postfix/local[3928]: 6844560FDB: to=<[email protected]>, relay=local, delay=0.18, delays=0.12/0.01/0/0.05, dsn=2.0.0, status=sent (delivered to mailbox)
Feb 4 15:06:08 localhost postfix/qmgr[3883]: 6844560FDB: removed
=> 没问题。
但如果我只使用邮件命令:
echo "test" | mail -s "test" guest
,邮件已发送,但 spamassassin 尚未解析该邮件,因为 syslog 显示以下内容:
Feb 4 15:09:36 localhost postfix/pickup[3881]: B6C1960DC0: uid=1000 from=<guest>
Feb 4 15:09:36 localhost postfix/cleanup[3956]: B6C1960DC0: message-id=<20150204140936.B6C1960DC0@localhost>
Feb 4 15:09:36 localhost postfix/qmgr[3883]: B6C1960DC0: from=<[email protected]>, size=339, nrcpt=1 (queue active)
Feb 4 15:09:36 localhost postfix/local[3957]: B6C1960DC0: to=<[email protected]>, orig_to=<guest>, relay=local, delay=0.18, delays=0.12/0/0/0.07, dsn=2.0.0, status=sent (delivered to mailbox)
Feb 4 15:09:36 localhost postfix/qmgr[3883]: B6C1960DC0: removed
一个主意 ?
衷心感谢。
答案1
对于队列后的内容过滤,postfix 有两种实现方法,简单内容过滤和高级内容过滤。你可以阅读这两种方法的解释在其官方文件中。
从你的问题中,我们可以了解到你使用了简单的内容过滤方法。符号是 的输出postconf -M
(或 的内容master.cf
)。它使用管道方法通过命令将电子邮件传递给垃圾邮件杀手
/usr/bin/spamc -u ${user} -e /usr/sbin/sendmail -oi -f ${sender} ${recipient}
Postfix 官方文档还告诉你简单内容过滤器的主要限制
第一个例子设置起来很简单,但有很大的局限性,将在第二个例子中解决。Postfix 使用 smtpd(8) 服务器从网络接收未过滤的邮件,并使用 Postfix pipe(8) 投递代理将未过滤的邮件投递到内容过滤器。内容过滤器使用 Postfix sendmail(1) 命令将过滤后的邮件重新注入 Postfix,以便 Postfix 可以将其投递到最终目的地。
这意味着通过 Postfix sendmail(1) 命令提交的邮件不能进行内容过滤。
因此,您看到的行为是正常的。
解决方案:如何对通过 mail 命令提交的电子邮件使用 content_filter?
您可以考虑切换您的设置以使用高级内容过滤方法。垃圾邮件杀手邮件列表中的此主题告诉你一些实现这一目标的替代方法:amavisd或者spamd 程序