その他/PostfixでSMTP AUTH over TLSを使う のバックアップソース(No.3)

*はじめに [#lb4283dc]

これまでSMTPサーバーにはGmailを使ってきましたが,GmailのSMTPサーバーを使ってtohgoroh.jpドメインのアドレスからメールを送信すると,From:にはtohgoroh.jpドメインのアドレスが記載されますが,Sender:にgmail.comドメインのアドレスが記載され,Outlookなど一部のメーラーで「代理で投稿しました」などと判断されてしまいます.

そこで,自分のサーバーをSMTPサーバーにして送信できるようにしました.


*インストール [#bed14af1]
#geshi(sh){{
# yum -y install postfix
# yum -y install openssl
# yum -y install cyrus*
}}

PostfixとOpensslは最新版にしました.
また,認証処理を行うCyrus SASLについては,関連するものを全てインストールしました.


*DNSの設定 [#o3294a9b]
example.comドメインからメールを送るため,MXレコードを設定しました.
(example.comは説明のための仮のドメインです.)

-mail.example.com A 300 ***.***.***.***
-example.com MX 300 mail.tohgoroh.jp


*SSL証明書の作成 [#dbf73d71]

SSL証明書は/etc/ssh/certsに置きました.

まず,秘密鍵を生成しました.
#geshi(sh){{
# openssl genrsa -out mail.example.com.key 2048
}}

つぎに,CSRファイルを生成しました.
#geshi(sh){{
# openssl req -new -key mail.example.com.key -out mail.example.com.csr
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:JP
State or Province Name (full name) []:Kanagawa
Locality Name (eg, city) [Default City]:Yokohama
Organization Name (eg, company) [Default Company Ltd]:ExampleCorp
Organizational Unit Name (eg, section) []:-
Common Name (eg, your name or your server's hostname) []:mail.example.com
Email Address []:

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
}}

Organizational Unit Nameにはハイフンを入力しました.
Email Address以後は入力していません.

このファイルがきちんとできていないと,正しく認証されないようです.
ハマりました.

最後に,自己証明書を生成しました.
#geshi(sh){{
# openssl x509 -days 3650 -req -signkey mail.example.com.key < mail.example.com.csr > mail.example.com.crt
}}

10年間(3650日)有効にしました.


*パスワードの設定 [#yeefc9aa]

#geshi(sh){{
# saslpasswd2 -c -u example.com user
# chown postfix /etc/sasldb2
}}

/etc/sasl2/smtpd.confを編集
#geshi(txt){{
pwcheck_method: auxprop
}}



*saslauthdの起動 [#b5ce8cbd]

#geshi(sh){{
# service saslauthd start
}}


サーバー起動時に自動的に起動するよう設定
#geshi(sh){{
# chconfig saslauthd on
}}


*Postfixの設定 [#r89968a9]

/etc/postfix/main.cfを編集して,以下の部分を最後に追加しました.
#geshi(txt){{
# SMTP-Auth
smtp_tls_CAfile = /etc/pki/tls/cert.pem
smtp_tls_cert_file = /etc/ssl/certs/mail.example.com.crt
smtp_tls_key_file = /etc/ssl/certs/mail.example.com.key
smtp_tls_session_cache_database = btree:/var/run/smtp_tls_session_cache
smtp_use_tls = yes
smtpd_tls_CAfile = /etc/pki/tls/cert.pem
smtpd_tls_cert_file = /etc/ssl/certs/mail.example.com.crt
smtpd_tls_key_file = /etc/ssl/certs/mail.example.com.key
smtpd_tls_received_header = yes
smtpd_tls_session_cache_database = btree:/var/run/smtpd_tls_session_cache
smtpd_use_tls = yes
tls_random_source = dev:/dev/uranium
smtpd_recipient_restrictions = permit_mynetworks,permit_sasl_authenticated,reject_unauth_destination
}}


最後にPostfixを再起動しました.
#geshi(sh){{
# /etc/init.d/postfix restart
}}

トップ   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS