CentOSではsendmailがデフォルトでインストールされていますが、MailDirが使えることや設定が容易なことからpostfixを導入してみます。
yumでインストールします。
/etc/postfix/main.cfを編集し、設定をおこないます。
# vi /etc/postfix/main.cf
ドメインを設定します。
mydomain = fujitoko.com
発信元の定義を設定します。
myorigin = $mydomain
外部に対しての送受信を許可します。
inet_interfaces = localhost
↓
inet_interfaces = all
ドメイン全体のメールサーバなので下記のように修正します。
mydestination = $myhostname, localhost.$mydomain, localhost
↓
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
Maildir形式にします。
home_mailbox = Maildir/
未承諾広告メールの対策でprocmailを使用するようにします。
mailbox_command = /usr/bin/procmail
SMTP名やバージョン番号を表示させないようにします。
smtpd_banner = $myhostname ESMTP unknown
SMTP-Authの設定を追加します。
smtpd_sasl_auth_enable = yes
smtpd_sasl_local_domain = $myhostname
smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination
メールサイズ制限の設定をします。
message_size_limit = 5242880
|
SMTP-Auth設定を有効にするためにsaslauthdを起動します。
| # /etc/rc.d/init.d/saslauthd start |
新規ユーザアカウント追加時にMaildirが作成されるようにします。
# mkdir -p /etc/skel/Maildir/cur
# mkdir -p /etc/skel/Maildir/new
# mkdir -p /etc/skel/Maildir/tmp
# chmod -R 700 /etc/skel/Maildir |
既存ユーザアカウントでメールディレクトリを作成しましょう。
$ mkdir ~/Maildir
$ cd Maildir
$ mkdir cur
$ mkdir new
$ mkdir tmp
$ cd ..
$ chmod -R 700 Maildir |
「未承諾広告※」の件名のメール対策の為、procmailの設定をします。
# vi /etc/procmailrc
SHELL=/bin/bash
PATH=/usr/bin:/bin
MAILDIR=$HOME/Maildir
DEFAULT=$MAILDIR/
LOGFILE=$HOME/procmaillog
DROPPRIVS=yes
:0
* ^Subject:.*iso-2022-jp
* ^Subject:\/.*
* ? echo "$MATCH" | nkf -mwZ2 | sed 's/[[:space:]]//g' | egrep '未承諾広告※'
/dev/null
|
procmaillogのローテンション設定をします。
# vi /etc/logrotate.d/procmail
/home/*/procmaillog{
missingok
nocreate
notifempty
} |
OP25B対策のため送信にはプロバイダのリレーサーバを中継するようにします。
# vi /etc/postfix/main.cf
relay_domains = $mydestination
relayhost = [プロバイダのリレーサーバ] |
sendmail停止しましょう。
| # /etc/rc.d/init.d/sendmail stop |
サーバ起動時にsendmailが起動しないようにします。
メールサーバー機能をsendmailからPostfixにします。
# alternatives --config mta
sendmail.postfixの番号を入力します。 |
postfixを起動させましょう。
| # /etc/rc.d/init.d/postfix start |
サーバ起動時に起動するようにします。
SMTPサーバの構築ができました。
|