メールサーバー Debian exim4 の smtp認証化
作成:2026-01-21 更新:2026-01-21ローカルで立ち上げてパソコンから利用していたメールサーバーを、
スマホからでも利用できるようにするためにsmtp認証を有効にした。
環境
debian 13.3
dovecot ver.2.4.1-4 (7d8c0e5759)
saslauthd 2.1.28
/etc/shadowを使い認証
最初,通常の検索, AI,マニュアルを調べsaslauthdで試みたがうまく行かず
sys-libs/pam-1.7.1-r2: breaks mail-mta/exim’s ability to authenticate users.
を見て eximと/etc/shadow のパーミッションの関係のようなので
dovecotを使うことに変更。
通常の検索, AIではうまく行かず,exim4.conf.templateの
auth/30_exim4-config_examples セクション
Use dovecot as authentication backend 以下を参照して設定したら動いた。
exim4の設定ファイルを分割しない場合は、以下のファイルを作る。
/etc/exim4/exim4.conf.localmacros
(分割の場合 /etc/exim4/conf.d/main/000_localmacros )
MAIN_TLS_ENABLE = true
/etc/exim4/exim4.conf.template で以下を有効にする。
dovecot_plain_server:
driver = dovecot
public_name = PLAIN
server_socket = /var/spool/exim4/dovecot.auth-client
server_set_id = $auth1
.ifndef AUTH_SERVER_ALLOW_NOTLS_PASSWORDS
server_advertise_condition = ${if eq{$tls_in_cipher}{}{}{*}}
.endif
/etc/dovecot/conf.d/10-auth.comf で以下を有効にする
auth_mechanisms = plain login
/etc/dovecot/conf.d/10-master.conf の service auth { に以下を追加する。
#SASL
unix_listener /var/spool/exim4/dovecot.auth-client {
mode = 0660
group = Debian-exim
}
/etc/dovecot/conf.d/10-ssl.conf の
ssl_server_cert_file
ssl_server_key_file
変更する。
ssl_server_cert_file = /etc/letsencrypt/live/[ドメイン名]/fullchain.pem
ssl_server_key_file = /etc/letsencrypt/live/[ドメイン名]/privkey.pem
念の為、証明書発行について 記す。
certbotで証明発行 自動更新する必要があるので
webサーバー(apache使用)をインストールしてホームページ配置用
ディレクトリ内に[認証用ディレクトリ]を作成して以下を実行
certbot certonly --webroot -d [ドメイン名] -w [認証用ディレクトリ]
certbotで証明書が自動更新された際、/etc/exim4/下の
exim.key,exim.crtが同期するようスクリプトを作成する。
exim4.sh
#!/usr/bin/bash
cp /etc/letsencrypt/live/[ドメイン名]/fullchain.pem /etc/exim4/exim.crt
chown root:Debian-exim /etc/exim4/exim.crt
chmod 640 /etc/exim4/exim.crt
cp /etc/letsencrypt/live/[ドメイン名]/privkey.pem /etc/exim4/exim.key
chown root:Debian-exim /etc/exim4/exim.key
chmod 640 /etc/exim4/exim.key
service exim4 reload
certbotが更新時に実行するディレクトリに配置する。
/etc/letsencrypt/renewal-hooks/deploy/exim4.sh
実行可能とする。
exim4.shを起動可能としテストする。
chmod 755 /etc/letsencrypt/renewal-hooks/deploy/exim4.sh
certbot --force-renewal
certbotの自動更新のタイマーが設置されているか以下で確認。
systemctl list-timers
