Postfix Amavisd-new SpamAssassin インストール


amavisd-newインストール
[root@centos ~]# yum -y install amavisd-new
amavisd.conf編集
[root@centos ~]# vi /etc/amavisd.conf
# @bypass_spam_checks_maps  = (1);  # controls running of anti-spam code
↓
@bypass_spam_checks_maps  = (1);  # controls running of anti-spam code ←コメント解除(スパムチェックを行わない)

$mydomain = 'example.com';   # a convenient default for other settings
↓
$mydomain = 'centos.orz';   # a convenient default for other settings ←変更(ドメイン名を指定)

$virus_admin               = "virusalert\@$mydomain";  # notifications recip.
↓
#$virus_admin               = "virusalert\@$mydomain";  # notifications recip. ←コメントアウト(ウイルス検知を管理者に通知しない)

↓下記をコメント解除
### http://www.clamav.net/
['ClamAV-clamd',
\&ask_daemon, ["CONTSCAN {}\n", "/var/run/clamav/clamd.sock"], ←変更(ソケットをclamdに合わせる)
qr/\bOK$/m, qr/\bFOUND$/m,
qr/^.*?: (?!Infected Archive)(.*) FOUND$/m ],
amavisd起動
[root@centos ~]# /etc/rc.d/init.d/amavisd start
[root@centos ~]# chkconfig amavisd on
[root@centos ~]# chkconfig --list amavisd
amavisd         0:off   1:off   2:on    3:on    4:on    5:on    6:off
main.cf編集
[root@centos ~]# vi /etc/postfix/main.cf
↓最終行に下記を記入
# Filter configuration
content_filter=smtp-amavis:[127.0.0.1]:10024
master.cf編集
[root@centos ~]# vi /etc/postfix/master.cf
↓最終行に下記を記入
# Amavis configuration
smtp-amavis unix -      -       n       -       2       smtp
    -o smtp_data_done_timeout=1200
    -o smtp_send_xforward_command=yes
    -o disable_dns_lookups=yes
    -o max_use=20
127.0.0.1:10025 inet n  -       n       -       -       smtpd
    -o content_filter=
    -o local_recipient_maps=
    -o relay_recipient_maps=
    -o smtpd_restriction_classes=
    -o smtpd_delay_reject=no
    -o smtpd_client_restrictions=permit_mynetworks,reject
    -o smtpd_helo_restrictions=
    -o smtpd_sender_restrictions=
    -o smtpd_recipient_restrictions=permit_mynetworks,reject
    -o smtpd_data_restrictions=reject_unauth_pipelining
    -o smtpd_end_of_data_restrictions=
    -o mynetworks=127.0.0.0/8
    -o smtpd_error_sleep_time=0
    -o smtpd_soft_error_limit=1001
    -o smtpd_hard_error_limit=1000
    -o smtpd_client_connection_count_limit=0
    -o smtpd_client_connection_rate_limit=0
SpamAssassin設定
[root@centos ~]# vi /etc/mail/spamassassin/v310.pre
#loadplugin Mail::SpamAssassin::Plugin::TextCat
↓
loadplugin Mail::SpamAssassin::Plugin::TextCat ←コメント解除(TextCatを有効にする)
SpamAssassin起動
[root@centos ~]# /etc/rc.d/init.d/spamassassin start
[root@centos ~]# chkconfig spamassassin on
[root@centos ~]# chkconfig --list spamassassin
spamassassin    0:off   1:off   2:on    3:on    4:on    5:on    6:off
SpamAssassinアップデート
[root@centos ~]# vi /etc/cron.daily/spamassassin
↓下記を記入
#!/bin/bash

cd /etc/mail/spamassassin
wget -qN http://tlec.linux.or.jp/docs/user_prefs || wget -qN http://www.flcl.org/~yoh/user_prefs
cp user_prefs local.cf
cat << EOF >> local.cf
report_safe 0
rewrite_header Subject ***SPAM***
EOF
/etc/rc.d/init.d/spamassassin restart > /dev/null
[root@centos ~]# chmod +x /etc/cron.daily/spamassassin [root@centos ~]# /etc/cron.daily/spamassassin [root@centos ~]# ll /etc/mail/spamassassin 合計 720 -rw-r--r-- 1 root root 1299 1月 8 10:22 init.pre -rw-r--r-- 1 root root 328085 1月 20 03:55 local.cf ←local.cfを確認 -rw-r--r-- 1 root root 64 1月 8 10:22 spamassassin-default.rc -rw-r--r-- 1 root root 35 1月 8 10:22 spamassassin-helper.sh -rw-r--r-- 1 root root 55 1月 8 10:22 spamassassin-spamc.rc -rw-r--r-- 1 root root 328071 1月 19 10:00 user_prefs -rw-r--r-- 1 root root 2602 1月 20 03:51 v310.pre -rw-r--r-- 1 root root 1195 1月 8 10:22 v312.pre -rw-r--r-- 1 root root 2416 1月 8 10:22 v320.pre
Postfix再起動
[root@centos ~]# /etc/rc.d/init.d/postfix restart
procmail設定 (POPの場合)
[root@centos ~]# vi /etc/procmailrc
↓下記を記入
SHELL=/bin/bash
PATH=/bin:/usr/bin
DROPPRIVS=yes
MAILDIR=$HOME/Maildir
DEFAULT=$MAILDIR/
LOGFILE=$MAILDIR/procmail.log

# 件名に「未承諾広告※」を含むメールを破棄
:0
* ^Subject:.*iso-2022-jp
* ^Subject:\/.*
* ? echo "$MATCH" | nkf -mwZ2 | sed 's/[[:space:]]//g' | egrep '未承諾広告※'
/dev/null

# ヘッダーに「X-Spam-***」がない場合、spamassassinを起動
:0fw
*!^X-Spam.*
|spamassassin
Outlook Expressの設定 (POPの場合)

1.上部メニューから「ツール」>「メッセージ ルール」>「メール」をクリック。

2.「新規作成」をクリック。

3.「件名に指定した言葉が含まれる場合」にチェックを入れ
「指定した言葉が含まれる」をクリック。

4.「***SPAM***」と入力して「追加」をクリック。

5.「OK」をクリック。

6.「指定したフォルダに移動する」にチェックを入れ
「指定したフォルダ」をクリック。

7.「新規フォルダ」をクリック。

8.「SPAM」と入力して「OK」をクリック。

9.「SPAM」を選択して「OK」をクリック。

10.「OK」をクリック。

11.「OK」をクリック。
既存ユーザー用スパムメールボックス作成(IMAPの場合)
[root@centos ~]# mkdir -p /home/user_name/Maildir/.spam/{cur,new,tmp}
[root@centos ~]# chmod -R 700 /home/user_name/Maildir/.spam
[root@centos ~]# chown -R user_name:user_name /home/user_name/Maildir/.spam
追加ユーザー用スパムメールボックス作成(IMAPの場合)
[root@centos ~]# mkdir -p /etc/skel/Maildir/.spam/{cur,new,tmp}
[root@centos ~]# chmod -R 700 /etc/skel/Maildir/.spam
procmailrc編集(IMAPの場合)
[root@centos ~]# vi /etc/procmailrc
↓下記を記入
SHELL=/bin/bash
PATH=/bin:/usr/bin
DROPPRIVS=yes
MAILDIR=$HOME/Maildir
DEFAULT=$MAILDIR/
SPAM=$MAILDIR/.spam/
LOGFILE=$MAILDIR/procmail.log
#VERBOSE=ON # 詳細ログ出力

# 件名に「未承諾広告※」を含むメールを破棄
:0
* ^Subject:.*iso-2022-jp
* ^Subject:\/.*
* ? echo "$MATCH" | nkf -mwZ2 | sed 's/[[:space:]]//g' | egrep '未承諾広告※'
/dev/null

# ヘッダーに「X-Spam-***」がない場合、spamassassinを起動
:0fw
*!^X-Spam.*
|spamassassin

# ヘッダーに「X-Spam-Status: Yes」がある場合、「.spam」ディレクトリに格納
:0
*^X-Spam-Status: Yes
$SPAM
スパムメール学習 (IMAPの場合)
[root@centos ~]# vi /etc/cron.daily/sa-learn
↓下記を記入
#!/bin/bash

# spamフォルダをスパムとして学習
/usr/bin/sa-learn --spam /home/*/Maildir/.spam/cur

# Maildirフォルダを通常のメールとして学習
/usr/bin/sa-learn --ham /home/*/Maildir/cur

# spamフォルダ削除する場合は下記をコメント解除
#/bin/rm -f /home/*/Maildir/.spam/cur/*
Outlook Expressの設定 (IMAPの場合)

1.「IMAPフォルダ」をクリック。

2.「リセット」をクリック。

3.「spam」フォルダを選択して「表示」をクリック。

4.「OK」をクリック。
スパムメール送信テスト
[root@centos ~]# echo "XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X"|mail user_name@centos.orz
Home PageTop