PostfixでSMTP AUTH over TLSを使う

2017-08-09 (水) 11:59:58 (2446d) | Topic path: Top / その他 / PostfixでSMTP AUTH over TLSを使う

はじめに

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

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

インストール

# yum -y install postfix
# yum -y install openssl
# yum -y install cyrus*

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

DNSの設定

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

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

SSL証明書の作成

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

まず,秘密鍵を生成しました.

# openssl genrsa -out mail.example.com.key 2048

つぎに,CSRファイルを生成しました.

# 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以後は入力していません.

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

最後に,自己証明書を生成しました.

# openssl x509 -days 3650 -req -signkey mail.example.com.key < mail.example.com.csr > mail.example.com.crt

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

パスワードの設定

# saslpasswd2 -c -u example.com user
# chown postfix /etc/sasldb2

/etc/sasl2/smtpd.confを編集

pwcheck_method: auxprop

saslauthdの起動

# service saslauthd start

サーバー起動時に自動的に起動するよう設定

# chconfig saslauthd on

Postfixの設定

/etc/postfix/main.cfを編集して,以下の部分を最後に追加しました.

# 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/lib/postfix/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/lib/postfix/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を再起動しました.

# /etc/init.d/postfix restart
トップ   編集 凍結解除 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS