自宅サーバー構築メモ The last update of this page 2011/11/01
インストール
パッケージインストール
yum install postfix
設定
Postfix設定
vi /etc/postfix/main.cf

自FQDN名
myhostname = mail.hosso.com

自ドメイン名
mydomain = hosso.com

ローカルからのメール送信時の送信元メールアドレス@以降にドメイン名を付加
myorigin = $mydomain

外部からのメール受信を許可
inet_interfaces = all

自ドメイン宛メールを受信できるようにする
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain

メールボックス形式をMaildir形式にする
home_mailbox = Maildir/

メールサーバーソフト名の隠蔽化
smtpd_banner = $myhostname ESMTP unknown

エイリアスの設定
alias_maps = hash:/etc/postfix/aliases
alias_database = hash:/etc/postfix/aliases

OP25B対策(プロバイダのSMTPサーバーを指定)
relayhost = [ プロバイダのSMTPサーバー名 ]:587

SMTP-Auth設定(最終行へ追加)
smtpd_sasl_auth_enable = yes
smtpd_sasl_local_domain = $myhostname
smtpd_recipient_restrictions = permit_mynetworks permit_sasl_authenticated reject_unauth_destination
smtpd_sasl_type = cyrus
smtpd_sasl_path = smtpd

OP25B対策(最終行へ追加)
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/authinfo
smtp_sasl_security_options = noanonymous
smtp_sasl_mechanism_filter = PLAIN, LOGIN

サブミッションポートを有効にする
vi /etc/postfix/master.cf

コメントアウトを取り除く
submission inet n - n - - smtpd
# -o smtpd_tls_security_level=encrypt
-o smtpd_sasl_auth_enable=yes
-o smtpd_client_restrictions=permit_sasl_authenticated,reject

SMTP-Auth設定
※SMTP-Auth用ユーザ名、パスワードにシステムのユーザ名、パスワードを使用する
saslauthd自動起動設定
chkconfig saslauthd on

saslauthd起動
/etc/rc.d/init.d/saslauthd start

SMTP認証情報設定
echo [ SMTPサーバー名 ]:587 ユーザー名 : パスワード > /etc/postfix/authinfo

root以外参照できないようにパーミッション変更
chmod 640 /etc/postfix/authinfo

authinfo.db作成

postmap /etc/postfix/authinfo

メールを利用するだけのログインできないユーザーを作成する
FTPは許可する場合
useradd -s /sbin/nologin username

SSH、FTP、シェル実行等すべて許可しない場合
useradd -s /bin/false username

新規ユーザ追加時にMaildir形式のメールボックスを作成する
Maildir形式メールボックス作成(作成したいユーザーで実行)
mkdir -p /home/ユーザー名/Maildir/{new,cur,tmp}

Maildirパーミッション設定
chmod -R 700 /home/ユーザー名/Maildir/

特定のユーザーのメールだけを受け取りたい場合
vi /etc/postfix/main.cf

/etc/postfix/local_recipientにエイリアス
local_recipient_maps = $alias_maps hash:/etc/postfix/local_recipient


vi /etc/postfix/local_recipient

許可したいメールアドレスのみ登録
username01@hosso.com OK
username02@hosso.com OK

postmapコマンドを実行して設定を/etc/postfix/local_recipient.dbに書き込み再起動
postmap /etc/postfix/local_recipient
/etc/init.d/postfix restart

エイリアスを設定する場合
vi /etc/postfix/aliases

エイリアス元:エイリアス先
root:hoso

postaliasコマンドを実行して設定を/etc/postfix/aliases.dbに書き込み再起動
postalias /etc/postfix/aliases
/etc/init.d/postfix restart