====== Postfix のインストール ======
SSH のログイン時にメールでアラートを飛ばしたいので、メールを送信するだけの目的で Postfix をインストールする。
==== インストール環境 ====
* Ubuntu 18.04.3 LTS 64bit
* お名前.com VPS (KVM) 1GB プラン
^ パッケージ名 ^ バージョン ^
| postfix | 3.3.0-1ubuntu0.2 |
===== インストール =====
必要なパッケージをインストールする。インストール中の設定について質問されるが、エンターキーを押してデフォルトをとりあえず設定する。
$ sudo apt install postfix
===== 設定 =====
==== 基本設定 ====
以下のコマンドで Postfix を設定するダイアログを起動する。
$ sudo dpkg-reconfigure postfix
* General type of mail configuration: Internet Site
* System mail name: hogepiyo.com
* Root and postmaster mail recipient: john #管理者ユーザー名#
* Other destinations to accept mail for (blank for none): hogepiyo.com, localhost.localdomain, localhost
* Force synchronous updates on mail queue?: No
* Local networks: 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
* Mailbox size limit (bytes): 0
* Local address extension character: +
* Internet protocols to use: all
==== メールボックス形式の設定 ====
Postfix の設定は /etc/postfix/main.cf を直接編集するか、設定用のコマンドを使う。
メールボックス形式をデフォルトの mbox から Maildir に変更する。
$ sudo postconf -e 'home_mailbox = Maildir/'
==== メール送信テスト ====
外部のメールアドレスにテストメールを送信して送信を確認する。
$ echo "Subject: sendmail test" | sendmail -v example@gmail.com
==== TLS でメールを暗号化して送信する ====
特に重要ではないと思うが、メールを暗号化して送信したい場合は [[certbot]] で証明書を取得した後、以下のコマンドを実行する。
$ sudo postconf -e 'smtpd_tls_cert_file = /etc/letsencrypt/live/example.com/fullchain.pem'
$ sudo postconf -e 'smtpd_tls_key_file = /etc/letsencrypt/live/example.com/privkey.pem'
$ sudo postconf -e 'smtp_tls_security_level = may'
$ sudo postconf -e 'smtpd_tls_security_level = may'
$ sudo postconf -e 'smtp_tls_note_starttls_offer = yes'
$ sudo postconf -e 'smtpd_tls_loglevel = 1'
$ sudo postconf -e 'smtpd_tls_received_header = yes'
===== 参考 =====
[[https://help.ubuntu.com/lts/serverguide/postfix.html|公式ドキュメント Postfix]]