PostfixでSMTP/SMTPSを構築してみる。認証システムはsaslauthdを使用する

saslauthdの設定

/usr/lib/sasl2/smtpd.confを設定

pwcheck_method: auxprop
auxprop_plugin: sasldb
mech_list: cram-md5 plain login

設定後、saslauthdのサービスを起動

証明書設定

SMTP over SSLで使用する証明書を生成する

openssl req -new -nodes -x509 -keyout server.key -out server.crt -days 365

プロトコルタイプを設定

/etc/postfix/master.cfに以下のように設定を行う

# SMTPのタイプ設定
smtp     inet  n       -       n       -       -       smtpd

# SMTP over SSLの設定
smtps    inet  n       -       n       -       -       smtpd
    -o smtpd_tls_wrappermode=yes
    -o smtpd_sasl_auth_enable=yes

※smtpsの部分がコメントされているのでコメントを削除する

OP25Bの設定

プロバイダがOP25Bを適応している場合は設定をしてないと外部送信が許可されないので、/etc/postfix/authinfoにプ ロバイダのサブミッションポートを設定する

[プロバイダのサーバー名]:587

場合によっては契約IDが必要になる。その場合は以下のように

[プロバイダのサーバー名]:587 契約ID:パスワード

更にmain.cfにもrelayhostを設定する

postfix本体の設定

/etc/postfix/main.cfを設定。基本設定するもののみ記述

# ドメイン名関連の設定
myhostname = hoge.com
mydomain = hoge.com
myorigin = $myhostname

# バインドするネットワーク?
inet_interfaces = all

# メールを受信するネットワーク?
mydestination = $myhostname,localhost.$mydomain,localhost,$mydomain

# メールリレーを許可するネットワーク
mynetworks = 128.0.0.0/8

# OP25B等でメールをリレーするサーバー
relayhost = [test.com]:587

# メールボックス設定
home_mailbox = Maildir/

# 接続時のサーバー情報。$mail_nameは消した方が良い
smtpd_banner = $myhostname ESMTP $mail_name

# smtpd関連の設定
smtpd_sasl_local_domain = $domain
smtpd_recipient_restrictions =
    permit_mynetworks,
    permit_sasl_authenticated,
    reject_unauth_destination
smtpd_sasl_auth_enable = yes

# saslauthd関連の設定
smtp_sasl_security_options = noanonymous
smtp_sasl_mechanism_filter = CRAM-MD5,PLAIN,LOGIN
broken_sasl_auth_clients = yes

# OP25Bの接続情報の設定
smtp_sasl_password_maps=hash:/etc/postfix/authinfo

# SSL関連設定
smtpd_tls_cert_file = /etc/postfix/certs/server.crt
smtpd_tls_key_file = /etc/postfix/certs/server.key
smtpd_use_tls = yes
smtpd_tls_ask_ccert = yes