SMTP3+POP3S メールサーバの構築

SMTP3+POP3S によるメールサーバの構築および運用はOSに依存するわけではないが、Postfix、Dovecotだけで構築できるものでもない。AlamaLinux8での構築手順を記録する。

参考資料:
メールサーバ構築 2025 AlamaLinux9
AlmaLinux9+AlmaLinux8+CentOS7
メールの送受信を暗号化するPOP3s/IMAP4s/SMTPs(over SSL)とは

SMTP3S+POP3Sについて

SMTPSとPOP3Sは、メールの送受信を暗号化するためのプロトコルです。SMTPSは、SMTPをSSL/TLSで暗号化したもので、メール送信時に使用されます。一方、POP3Sは、POP3をSSL/TLSで暗号化したもので、メール受信時に使用されます。これにより、メールの送受信時のセキュリティが向上します。

SMTPS (SMTP over SSL/TLS):

  • メール送信プロトコルであるSMTPをSSL/TLSで暗号化したもの
  • メールクライアントからメールサーバーへの送信を暗号化
  • 通常、ポート465番を使用
  • セキュリティのためには、STARTTLSよりもSMTPSを推奨する場合がある

POP3S (POP3 over SSL/TLS):

  • メール受信プロトコルであるPOP3をSSL/TLSで暗号化したもの
  • メールサーバーからメールクライアントへの受信を暗号化
  • 通常、ポート995番を使用
  • メールをローカルに保存しるPOP3の動き

SMTP3+POP3Sでのサービス仕様

クラウド:さくらのクラウド
メールアドレスのドメイン名 aq3v2.aquila.jp
メールサーバのアドレス(FQDN) aq3v2.aquila.jp
メールサーバのIPアドレス 163.43.230.128
サーバOS AlmaLinux release 8.10
メール送信サーバ Postfix(SMTP-Auth over SSL or Submission(SMTP-AUTH) 587 STARTTLS)
メール受信サーバDovecot(IMAPS、POP3S)
SSL:Let's Encrypt(Webサーバなし)

SMTP3+POP3S サーバ構築ログ

dnf update
dnf groupinstall base
dnf groupinstall development

dnf install postfix
dnf install dovecot

systemctl stop firewalld
systemctl disable firewalld

dnf install certbot

Webサーバが無い場合の鍵構築

certbot certonly --standalone \
-d aq3v2.aquila.jp \
-m certbot@aq3v2.aquila.jp \
--agree-tos -n

crontab -e
00 05 01 * * root /bin/certbot renew --force-renewal && /bin/systemctl reload postfix && /bin/systemctl reload dovecot

Postfix Configuration

cp -ip /etc/postfix/main.cf /etc/postfix/main.cf.org
vi /etc/postfix/main.cf

基本設定を行い

TLS CONFIGURATIONをすべてコメントにする(最下部にまとめて設定)

smtp_tls_security_level = may
meta_directory = /etc/postfix
shlib_directory = /usr/lib64/postfix

message_size_limit = 20480000
mailbox_size_limit = 0
allow_mail_to_commands = alias,forward,include
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
broken_sasl_auth_clients = yes
smtpd_sasl_local_domain = $mydomain
smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination

smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
smtpd_sasl_authenticated_header = yes
smtpd_tls_auth_only = yes
smtputf8_enable = no
smtpd_tls_cert_file = /etc/letsencrypt/live/aq4.aquila.jp/fullchain.pem
smtpd_tls_key_file = /etc/letsencrypt/live/aq4.aquila.jp/privkey.pem
smtpd_use_tls = yes
smtpd_tls_security_level = may
smtpd_tls_loglevel = 1
smtpd_tls_received_header = yes
smtp_tls_CAfile = /etc/ssl/certs/ca-bundle.crt
smtp_tls_CApath = /etc/ssl/certs

dnf reinstall ca-certificates
update-ca-trust force-enable
update-ca-trust extrac

cp /etc/postfix/master.cf /etc/postfix/master.cf.org
vi /etc/postfix/master.cf

postfix check

systemctl start postfix
systemctl enable postfix

DovecotによるSMTP認証

vi /etc/dovecot/users/passwd
smtpauth:{PLAIN}password$

useradd -r -u 200 -g mail -d /var/mail -s /sbin/nologin vmail

chown dovecot:dovecot /etc/dovecot/users/passwd
sudo chmod 600 /etc/dovecot/users/passwd

Dovecot Configuration

cp /etc/dovecot/conf.d/10-auth.conf /etc/dovecot/conf.d/10-auth.conf.org
vi /etc/dovecot/conf.d/10-auth.conf

cp /etc/dovecot/conf.d/auth-passwdfile.conf.ext /etc/dovecot/conf.d/auth-passwdfile.conf.ext.org
vi /etc/dovecot/conf.d/auth-passwdfile.conf.ext

cp /etc/dovecot/conf.d/10-ssl.conf /etc/dovecot/conf.d/10-ssl.conf.org
vi /etc/dovecot/conf.d/10-ssl.conf

cp /etc/dovecot/conf.d/10-mail.conf /etc/dovecot/conf.d/10-mail.conf.org
vi /etc/dovecot/conf.d/10-mail.conf

cp /etc/dovecot/conf.d/10-master.conf /etc/dovecot/conf.d/10-master.conf.org
vi /etc/dovecot/conf.d/10-master.conf

systemctl start dovecot
systemctl enable dovecot