next up previous contents
Next: 安全機制 Up: Mail Server Previous: Postfix 架設   Contents

垃圾郵件過濾

  1. postfix 雖可過濾字串,來阻擋垃圾郵件,但當郵件內容以 base64 編碼時,卻無法動作。
  2. 安裝 spamassassin
    [root@mail ~]# yum install spamassassin
    
  3. 編輯設定檔
    [root@mail ~]# cat /etc/mail/spamassassin/local.cf
    # These values can be overridden by editing ~/.spamassassin/user_prefs.cf 
    # (see spamassassin(1) for details)
    
    # These should be safe assumptions and allow for simple visual sifting
    # without risking lost emails.
    
    required_hits 5
    report_safe 0
    rewrite_header Subject [SPAM]
    blacklist_from	*@yahoo-inc.com
    blacklist_from	*@goisa.it
    blacklist_from	*@moopex.cz
    
  4. 查詢設定檔編輯說明
    [root@mail ~]# man Mail::SpamAssassin::Conf
    
  5. 新增 spamd 群組及帳號
    [root@mail ~]# groupadd spamd
    [root@mail ~]# useradd -g spamd -s /bin/false -d /var/log/spamassassin spamd
    [root@mail ~]# chown spamd:spamd /var/log/spamassassin
    
  6. 編輯 postfix 的設定檔,將 spamassassin 整合進 postfix。
    [root@mail ~]# vim /etc/postfix/master.cf
    [root@mail ~]# grep 'spamassassin' /etc/postfix/master.cf -B4 
    # ==========================================================================
    # service type  private unpriv  chroot  wakeup  maxproc command + args
    #               (yes)   (yes)   (yes)   (never) (100)
    # ==========================================================================
    smtp      inet  n       -       n       -       -       smtpd -o content_filter=spamassassin
    --
    #
    #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 flags=R user=spamd argv=/usr/bin/spamc -e /usr/sbin/sendmail -oi -f ${sender} ${recipient}
    
  7. 啟動 sapmassassin 前更新 spam rules。
    [root@mail ~]# sa-update && /etc/init.d/spamassassin restart
    
  8. postfix 及 spamassassin 重新載入或啟動
    [root@mail ~]# /etc/init.d/postfix reload
    Reloading postfix:                                         [  OK  ]
    [root@mail ~]# /etc/init.d/spamassassin restart
    Stopping spamd:                                            [  OK  ]
    Starting spamd:                                            [  OK  ]
    
  9. postfix 及 spamassassin 重新載入或啟動
    [root@mail1 ~]# vim /etc/mail/spamassassin/custom_rule.cf
    header LOCAL_EVERYTHINGYOUNEED_RULE Subject=~ /Everything you need, you can find here/i
    score LOCAL_EVERYTHINGYOUNEED_RULE 3.0
    describe LOCAL_EVERYTHINGYOUNEED_RULE Everything you need
    [root@mail1 ~]# spamassassin -D --lint
    



2018-04-25