- 安装程序
sudo yum install spamassassin
- 编辑/etc/mail/spamassassin/local.cf
required_hits 5.0
report_safe 0
required_score 5
rewrite_header Subject [SPAM]
- 创建用户、组
groupadd spamd
useradd -g spamd -s /bin/false -d /var/log/spamassassin spamd
chown spamd:spamd /var/log/spamassassin
- Selinux设置
sudo chcon -Rt user_home_t /var/log/spamassassin
不然会报错。
- 更新规则
sudo sa-update
- 启动服务
sudo systemctl enable spamassassin
sudo systemctl start spamassassin
如果启动出错,很可能是规则没更新,看出错提示吧。
- 编辑/etc/postfix/master.cf
在smtpd后面加上-o content_filter=spamassassin,如下:
smtp inet n - n - - smtpd -o content_filter=spamassassin
smtps inet n - n - - smtpd -o content_filter=spamassassin
并在文档最后加入下面的代码:
spamassassin unix - n n - - pipe flags=R user=spamd argv=/usr/bin/spamc -e /usr/sbin/sendmail -oi -f ${sender} ${recipient}
- 重启服务
sudo systemctl restart postfix
sudo systemctl restart spamassassin
- 检测服务是否正常启动 这个代码能马上看到服务运行情况:
journalctl | grep spam
这个代码,要过一阵子才能看到情况:
ss -tnlp | grep spamd
- 设置每天自动更新规则
sudo crontab -e
00 01 * * * root /bin/sa-update && /sbin/service spamassassin restart
参考文档: http://forums.sentora.org/showthread.php?tid=1118 https://janikarhunen.fi/tackle-spam-with-spamassassin-on-centos7-and-postfix.html