目次

Postfix のインストール

SSH のログイン時にメールでアラートを飛ばしたいので、メールを送信するだけの目的で Postfix をインストールする。

インストール環境

パッケージ名 バージョン
postfix 3.3.0-1ubuntu0.2

インストール

必要なパッケージをインストールする。インストール中の設定について質問されるが、エンターキーを押してデフォルトをとりあえず設定する。

$ sudo apt install postfix

設定

基本設定

以下のコマンドで Postfix を設定するダイアログを起動する。

$ sudo dpkg-reconfigure postfix

メールボックス形式の設定

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'

参考

公式ドキュメント Postfix