わりと鬼門のメールサーバ構築。
ハマりどころがたくさんあるし保守/運用も手間がかかるから、
あまりやりたくない作業の一つではある。
Contents
ワイルドカードのSSL証明書を letsencrpy で作る
*.wpken.net
で証明書を作る。
1 2 |
$ sudo certbot-auto certonly --manual -d *.wpken.net -m yokada-admin@wpken.net --agree-tos --manual-public-ip-logging-ok --preferred-challenges dns-01 --server https://acme-v02.api.letsencrypt.org/directory |
以下は実行ログ
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
<br /> Saving debug log to /var/log/letsencrypt/letsencrypt.log Plugins selected: Authenticator manual, Installer None Obtaining a new certificate Performing the following challenges: dns-01 challenge for wpken.net - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Please deploy a DNS TXT record under the name _hogepiyo-example.wpken.net with the following value: hogeIIAJVIJoFuFagoIUwerhogeIIAJVIJoFuFagoIUwerh Before continuing, verify the record is deployed. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Press Enter to Continue |
ここで、すぐにエンターを押さないこと!
DNSのTXTレコードを追加する作業をやらないとエラーになります。
以下は失敗したときのログ:
1 2 3 4 5 6 7 8 9 10 11 12 |
<br /> Waiting for verification... Cleaning up challenges Failed authorization procedure. wpken.net (dns-01): urn:ietf:params:acme:error:dns :: DNS problem: NXDOMAIN looking up TXT for xxxx.wpken.net IMPORTANT NOTES: - The following errors were reported by the server: Domain: wpken.net Type: None Detail: DNS problem: NXDOMAIN looking up TXT for xxxx.wpken.net |
Route 53 で TXTレコードを追加する。
以下のレコードを追加します。
- Name: _hogepiyo-example.wpken.net
- Value: “hogeIIAJVIJoFuFagoIUwerhogeIIAJVIJoFuFagoIUwerh”
ターミナル画面に戻ってエンターキーを押して再開
証明書生成成功ログ:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
<br /> Waiting for verification... Cleaning up challenges IMPORTANT NOTES: - Congratulations! Your certificate and chain have been saved at: /etc/letsencrypt/live/wpken.net-0001/fullchain.pem Your key file has been saved at: /etc/letsencrypt/live/wpken.net-0001/privkey.pem Your cert will expire on 2018-12-07. To obtain a new or tweaked version of this certificate in the future, simply run certbot-auto again. To non-interactively renew *all* of your certificates, run "certbot-auto renew" - If you like Certbot, please consider supporting our work by: Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate Donating to EFF: https://eff.org/donate-le |
2つのファイルが生成されました。これをメールサーバーの設定ファイルに記述します。(下記参照)
- /etc/letsencrypt/live/wpken.net-0001/fullchain.pem
- /etc/letsencrypt/live/wpken.net-0001/privkey.pem
それでは、メールサーバー(Posftfix + Dovecot)をインストール+設定します。
Installing packages
以下 Lightsailにsshでログインして作業します。
1 2 |
$ sudo apt-get install postfix dovecot-core dovecot-imapd dovecot-pop3d |
なぞの QTE的なウィンドウ が出現
- とりあえず Internet site を選択した。
- FQDNを入力: mail.wpken.net
これで必要なソフトウェアのインストール完了。
Postfixの設定
以下略
- /etc/postfix/main.cf
- /etc/postfix/master.cf
Dovecotの設定
以下略:
- /etc/dovecot/dovecot.conf
- /etc/dovecot/conf.d/10-master.conf
- /etc/dovecot/conf.d/10-auth.conf
- /etc/dovecot/conf.d/10-mail.conf
- /etc/dovecot/conf.d/10-ssl.conf
- /etc/dovecot/conf.d/auth-static.conf.ext
virtual mailbox、メールユーザの設定
以下略
imapとpop3 認証ユーザの設定
以下略
Route 53 でポート開ける
Lightsailの管理画面でファイアウォールのところで開放したいポートを指定します。
- 25 (TCP)
- 465 (TCP) SMPT over SSL
- 993 (TCP) IMAP4S (IMAP over SSL)
Route 53 の設定(2)
以下レコード追加し、メールサーバーをDNSに紐づけます。
- Aレコード追加: mail.wpken.net 「パブリックIPアドレス」
- MXレコード追加: wpken.net 10 mail.wpken.net. (末尾のドットを忘れずに)
WordPressからメールを送れるようにする
wp-mail-smtp プラグインをインストールする。
1 2 3 |
$ cd /opt/bitnami/apps/wordpress/htdocs $ wp plugin install wp-mail-smtp --activate |
wp-mail-smtp プラグインを設定する
- From Email: メールサーバ設定時に作成したユーザーのメールアドレス
- メーラー: Other SMTP
メーラーの詳細設定は以下のようにします:
テスト送信
送信できるかテストしてみましょう。
メールクライアントでの設定
Apple Mail では CRAM-MD5 認証がうまくいかなかったです。
なので Thunderbird を使いました。
メールサーバーチェック
以下のサイトを使って 踏み台にされないようになっているか確認してみましょう。
Email Server Test – Online SMTP diagnostics tool – MxToolbox
実際に試す
Aboutページからメールが送られるか試す:
ok
こちらからは以上です。
細かい設定については調べればでてくるので省略しました。
需要ありそうなら公開します。
No comment yet, add your voice below!