NixOSでPostfixとDovecotによるメールサーバの構築 - SASL認証編

前回の記事では、VirtualBoxで新規に立ち上げたNixOSにメール転送エージェントPostfixとメール配信エージェントDovecotをインストールし、メールサーバを構築した。そして動作確認としてクライアント側にnPOPという電子メールクライアントをインストールしメールの送受信を行なった。しかし、その際に構築したメールサーバはTLSおよびSASLの機能が無効化されたものであり、セキュリティ面ではほぼ無防備なものであった。
今回は、前回の記事にて構築したメールサーバにてTLSおよびSASLの設定を有効にし、クライアント側にてメール送受信による動作確認を行なった。
過去の記事について NixOSネタの記事の一覧は、当記事内最下部の「NixOS関連の記事」欄内を参照。
 
前回の記事は以下のリンク先を参照。
https://debslink.hatenadiary.jp/entry/20250418/1744924524 NixOSでPostfixとDovecotによるメールサーバの構築
 


SASL認証について
SASL認証とはSimple Authentication and Security Layer(簡易認証セキュリティ層)の略称で、IMAPやPOPやLDAP等のような通信に関わるアプリケーションプロトコルにユーザ認証の機能を提供するフレームワークである。例えばPostfix+Dovecotの環境でSASLを有効にすると、以下のような利点が有る。
・SMTP-AUTHによるユーザ認証の実現:SMTPクライアントからの送信時にユーザ認証が可能になる
・TLS接続など暗号化された通信の実現:TLSと組み合わせると認証情報を暗号化された送信が可能になる
・外部の認証システムとの連携が可能:LDAPやOAuthなどと連携する事でログイン情報の一元管理が可能になる
 


OpenSSLとcacertのインストール
前回の記事の終了の段階では、SASL認証に必要なパッケージがNixOSに導入されていない状態であった。当環境のメールサーバにてSASL認証を利用するにはOpenSSLとcacertのパッケージをインストールする必要が有る。
・openssl:OpenSSLのパッケージ
・cacert:X509の規格で証明書の発行やCA秘密鍵の生成等に必要なパッケージ

まずはOpenSSLとcacertをインストールする設定を/etc/nixos/configuration.nix ファイルに記載する。
尚、NixOSにおいてPostfixとDovecotにTLSおよびSASLを有効にする場合は、他のパッケージとは異なり、OpenSSLとcacertの.nixファイルの作成および/etc/nixos/configuration.nixファイルに設定値を追記する必要は無い。

[testsv99:~ ]# sudo nvim /etc/nixos/configuration.nix 

# Edit this configuration file to define what should be installed on
# your system.  Help is available in the configuration.nix(5) man page
# and in the NixOS manual (accessible by running ‘nixos-help’).
:
省略
:
  # List packages installed in system profile. To search, run:
  # $ nix search wget
  environment.systemPackages = with pkgs; [
  #  vim # Do not forget to add an editor to edit configuration.nix! The Nano editor is also installed by default.
  #  wget
  zsh
  neovim
  chrony
  dovecot
  postfix
  openssl  ◻️◻️追記
  cacert  ◻️◻️追記
  ];
:
省略
:

 
以上をもって、OpenSSLとcacertのインストールの準備が出来た。
ここでsudo nixos-rebuild switchを実行し、NixOSにOpenSSLとcacertをインストールする。

[testsv99:~ ]# sudo nixos-rebuild switch 
building Nix...
building the system configuration...
these 11 derivations will be built:
  /nix/store/7smdbxp1kjgmafxk8hw99hsan5ff1ry9-system-path.drv
  /nix/store/2xaks5rgp9z23q3b4wsbfjzcgxpvwakv-dbus-1.drv
  /nix/store/ilff489zvvfsfqvlkq2mip0vxc051ly5-X-Restart-Triggers-dbus.drv
:
省略
:
activating the configuration...
setting up /etc...
reloading user units for hechtia...
restarting sysinit-reactivation.target
reloading the following units: dbus.service
the following new units were started: run-credentials-systemd\x2dtmpfiles\x2dresetup.service.mount, sysinit-reactivation.target, systemd-tmpfiles-resetup.service
[testsv99:~ ]# 

 
sudo nixos-rebuild switchがエラーを吐かず正常に完了したら、以下のコマンドを叩きOpenSSLが正常にインストールされた事を確認する。

[testsv99:~ ]# openssl -v
OpenSSL 3.3.3 11 Feb 2025 (Library: OpenSSL 3.3.3 11 Feb 2025)
[testsv99:~ ]# 

 


SSL自己署名証明書の発行
当メールサーバにてSASL認証を利用するので、SSLサーバ証明書を作成する必要が有る。本来であればサーバ証明書を業者から購入する必要が有るのだが、当メールサーバは家庭環境内での利用であり外部に公開しない為、自己署名な証明書を作成する必要が有る。
まず最初に、自己署名証明書の作成の為の作業用ディレクトリsslを作成し、sslディレクトリに移動する。

[testsv99:~ ]# mkdir ~/ssl                           
[testsv99:~ ]# cd ssl
[testsv99:~/ssl ]# 

 
続いて、秘密鍵を作成する。
鍵長は2048ビット、秘密鍵のファイル名はserver.keyとする。
続いてlsコマンドを叩き、秘密鍵server.keyファイルが存在する事を確認する。

[testsv99:~/ssl ]# openssl genrsa 2048 > server.key
[testsv99:~/ssl ]# 
[testsv99:~/ssl ]# ls                                
total 12
drwxr-xr-x 2 hechtia users 4096 Apr 18 13:02 .
drwx------ 4 hechtia users 4096 Apr 18 13:00 ..
-rw-r--r-- 1 hechtia users 1704 Apr 18 13:02 server.key
[testsv99:~/ssl ]# 

 
続いて、公開鍵を作成する。
公開鍵はSSLサーバ証明書への署名に関する情報が含まれている。
公開鍵のファイル名はserver.csr、署名に関する情報はCountry Name (2 letter code)以下で入力する。

[testsv99:~/ssl ]# openssl req -new -key server.key > server.csr
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:JP
State or Province Name (full name) [Some-State]:TOKYO
Locality Name (eg, city) []:UNKNOWN
Organization Name (eg, company) [Internet Widgits Pty Ltd]:HOGEHOGE
Organizational Unit Name (eg, section) []:
Common Name (e.g. server FQDN or YOUR name) []:testsv99.local
Email Address []:

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
[testsv99:~/ssl ]# 

 
上記で情報を入力しEnterキーを叩くと、公開鍵が生成される。
lsコマンドを叩き、公開鍵server.csrファイルが存在する事を確認する。

[testsv99:~/ssl ]# ls
total 16
drwxr-xr-x 2 hechtia users 4096 Apr 19 09:52 .
drwx------ 3 hechtia users 4096 Apr 19 09:51 ..
-rw-r--r-- 1 hechtia users  993 Apr 19 09:53 server.csr
-rw-r--r-- 1 hechtia users 1704 Apr 19 09:50 server.key
[testsv99:~/ssl ]# 

 
続いて、電子証明書を作成する。
電子証明書は、公開鍵とその所有者の情報を紐付けするものであり公開鍵が正しいことを証明する。
以下の例では、電子証明書をITU-T X509の規格、有効期限10年、電子証明書のファイル名server.crtで生成している。
電子証明書の生成後、lsコマンドを叩き電子証明書のファイルserver.crtが存在する事を確認する。

[testsv99:~/ssl ]# openssl x509 -req -days 3650 -signkey server.key < server.csr > server.crt
Certificate request self-signature ok
subject=C=JP, ST=TOKYO, O=MYHOME, OU=MYUNIT, CN=testsv99.local
[testsv99:~/ssl ]# 
[testsv99:~/ssl ]# ls                               
total 20
drwxr-xr-x 2 hechtia users 4096 Apr 18 13:05 .
drwx------ 4 hechtia users 4096 Apr 18 13:00 ..
-rw-r--r-- 1 hechtia users 1237 Apr 18 13:05 server.crt
-rw-r--r-- 1 hechtia users  989 Apr 18 13:05 server.csr
-rw-r--r-- 1 hechtia users 1704 Apr 18 13:02 server.key
[testsv99:~/ssl ]#                                  

 
最後に、上記で作成した電子証明書server.crtと秘密鍵server.keyをPostfixが読み取れるディレクトリにコピーする。

[testsv99:~/ssl ]# sudo ls /etc/ssl/certs      
ca-bundle.crt  ca-certificates.crt
[testsv99:~/ssl ]# 
[testsv99:~/ssl ]# sudo cp server.crt /etc/ssl/certs/server.crt
[testsv99:~/ssl ]# 
[testsv99:~/ssl ]# sudo cp server.key /etc/ssl/certs/server.key 
[testsv99:~/ssl ]# cd
[testsv99:~ ]#
[testsv99:~ ]# ls /etc/ssl/certs 
total 16
drwxr-xr-x 2 root root 4096 Apr 19 09:55 .
drwxr-xr-x 3 root root 4096 Apr 19 09:48 ..
lrwxrwxrwx 1 root root   35 Apr 19 09:48 ca-bundle.crt -> /etc/static/ssl/certs/ca-bundle.crt
lrwxrwxrwx 1 root root   41 Apr 19 09:48 ca-certificates.crt -> /etc/static/ssl/certs/ca-certificates.crt
-rw-r--r-- 1 root root 1245 Apr 19 09:55 server.crt
-rw-r--r-- 1 root root 1704 Apr 19 09:55 server.key
[testsv99:~ ]# 

 

メールサーバの設定変更
電子証明書と秘密鍵の準備が出来たところで、PostfixとDovecotの認証周りの設定を前回の記事の内容から一部変更する必要が有る。
 
1. Postfixの設定変更
以下はPostfixの設定ファイル/etc/nixos/postfix.nixの内容。

前回の記事にて公開した設定内容との差分は以下のとおり。
・smtp_use_tlsをnoからyesに変更
・smtp_sasl_auth_enableをnoからyesに変更
・smtpd_sasl_type とそこから下の設定の行頭のコメントアウトを外した
・smtpd_sasl_pathで記載されているPATHを修正
・smtp_tls_CAfileはfindコマンドで検索し、/etc/ssl/certs/ca-bundle.crtを含むPATHに修正

※以下の設定例は行数多めにつき、Webブラウザによって全て表示しきれない事があります。その場合は黒塗りの箇所をスクロールする事で終わりまで表示する事が出来ます。

[testsv99:~ ]# sudo nvim /etc/nixos/postfix.nix        
{ config, pkgs, lib, ... }:
{
  services.postfix = {
    enable = true;
    #relayHost = "smtp.gmail.com";
    #relayPort = 587;
    config = {
      myhostname = "testsv99.local";
      mydomain = "local";
      inet_interfaces = "all";
      inet_protocol = "ipv4";
      mail_owner = "postfix";
      myorigin = "$mydomain";

      sendmail_path = "/nix/store/ynccbl3k3p3b3gr38sxhkgqjfmlgz5a7-postfix-3.9.3/bin/sendmail";
      mailq_path = "/nix/store/ynccbl3k3p3b3gr38sxhkgqjfmlgz5a7-postfix-3.9.3/bin/mailq;";
      #newaliases_path = "/usr/bin/newaliases.postfix";
      setgid_group = "postdrop";
      html_directory = "no";
      #manpage_directory = "/usr/share/man";
      #sample_directory = "/usr/share/doc/postfix/samples";

      mydestination = [
        "$myhostname" "localhost.$mydomain" "localhost" "$mydomain"
      ];
      mynetworks = [
        "10.0.0.0/8" "172.16.0.0/12" "192.168.0.0/16" "127.0.0.0/8"
      ];
      home_mailbox = "/Maildir";

      smtp_use_tls = "yes";
      smtp_sasl_auth_enable = "yes";
      broken_sasl_auth_clients = "yes";
      smtp_sasl_security_options = "";

      disable_vrfy_command = "yes";
      smtpd_helo_required = "yes";

      smtpd_sasl_type = "dovecot";
      smtpd_sasl_path = "/run/dovecot2/auth-login";
      smtpd_sasl_security_options = "noanonymous";
      smtpd_sasl_local_domain = "$myhostname";
      smtpd_relay_restrictions = [
        "permit_mynetworks" "permit_sasl_authenticated" "reject_unauth_destination"
      ];
      smtpd_tls_cert_file = "/etc/ssl/certs/server.crt";
      smtpd_tls_key_file = "/etc/ssl/certs/server.key";
      smtpd_tls_security_level = "may";
      smtp_tls_CAauth = "/etc/pki/tls/certs/";
      smtp_tls_CAfile = "/nix/store/g5zffs84ia8kn5azkl2l3a2q3f47flxw-nss-cacert-3.108/etc/ssl/certs/ca-bundle.crt";
      smtpd_sasl_auth_enable = true;
     };
  };
}
[testsv99:~ ]#

 

2. Dovecotの設定変更
続いてDovecotの設定ファイル/etc/nixos/dovecot2.nixの内容。

前回の記事にて公開した設定内容との差分は以下のとおり。
・sslをnoからyesに変更
・ssl_certの行とssl_keyの行を追加

※以下の設定例は行数多めにつき、Webブラウザによって全て表示しきれない事があります。その場合は黒塗りの箇所をスクロールする事で終わりまで表示する事が出来ます。

[testsv99:~ ]# sudo nvim /etc/nixos/dovecot2.nix       
{
  services.postfix = {
    enable = true;
  };
  services.dovecot2 = {
    enable = true;
    enablePop3 = true;
    enableImap = true;
    enableLmtp = true;
    protocols = [ "imap" "pop3" ];
  };
  #services.dovecot2.mailLocation = "maildir:~/.mail";
  services.dovecot2.mailLocation = "/var/spool/mail/hechtia";
  services.dovecot2.extraConfig = ''
    listen = *
    disable_plaintext_auth = no
    auth_mechanisms = plain login
    ssl = yes
    ssl_cert = </etc/ssl/certs/server.crt
    ssl_key = </etc/ssl/certs/server.key
    namespace inbox {
      inbox = yes
      }
    service imap-login {
      inet_listener imap {
        port = 143
      }
    }
    service pop3-login {
      inet_listener pop3 {
        port = 110
      }
    }
    service lmtp {
      inet_listener lmtp {
        port = 24
	ssl = yes
      }
    }
 '';
}
[testsv99:~ ]# 

 
Dovecotの設定ファイル/etc/nixos/dovecot2.nixの設定変更を終えたら、SASL認証のファイルのアクセス権限を変更する。このファイルが無い場合、環境によってPATHやファイル名が違う事があるようなので注意。

[testsv99:~ ]# sudo chmod 777 /run/dovecot2/auth-login
[testsv99:~ ]#

 
ここまで来たら、SASL認証が有効なPostfix+Dovecotなメールサーバの準備が完了である。
sudo nixos-rebuild switchコマンドを叩き、設定内容をシステムに反映させる。

[testsv99:~ ]# sudo nixos-rebuild switch 
building Nix...
building the system configuration...
these 9 derivations will be built:
  /nix/store/v6rl1lsc43yd62bhprkz9hlf88gm6n5l-postfix-main.cf.drv
  /nix/store/plymyvra1wcsn43h87v7i7flmr1wcpkx-unit-script-postfix-setup-start.drv
  /nix/store/j7yghq30jqfck5ss29ix4lv6l49qvzix-unit-postfix-setup.service.drv
:
省略
:
activating the configuration...
setting up /etc...
reloading user units for hechtia...
restarting sysinit-reactivation.target
starting the following units: dovecot2.service, postfix-setup.service
[testsv99:~ ]# 

 

3. PostfixサービスとDovecotサービスの再起動と確認
sudo nixos-rebuild switch コマンドが問題無く実行完了したら、PostfixサービスとDovecotサービスを再起動させる。

[testsv99:~ ]# sudo systemctl restart postfix
[testsv99:~ ]# 
[testsv99:~ ]# sudo systemctl restart dovecot2
[testsv99:~ ]# 

 
続いてsudo systemctl status postfixコマンドを叩く。起動直後のPostfixのサービスのステータスおよびログは以下のとおりである。

Active:の行がactive (running)になっている事と、下側に出力されているログにエラーが無い事を確認する。
尚、「warning: /etc/postfix/main.cf: support for parameter "smtp_use_tls" will be removed; instead, specify "smtp_tls_security_level"」のログが3行出力されているが、これは/etc/nixos/postfix.nixファイル内にあるsmtp_use_tlsの設定が近いうちに無くなるのでsmtp_tls_security_levelに置き換えてね...という意味である。

[testsv99:~ ]# sudo systemctl status postfix 
● postfix.service - Postfix mail server
     Loaded: loaded (/etc/systemd/system/postfix.service; enabled; preset: ignored)
     Active: active (running) since Sat 2025-04-19 10:05:29 JST; 1min 0s ago
 Invocation: 41949e5692594be2a826376559860435
    Process: 6931 ExecStart=/nix/store/ynccbl3k3p3b3gr38sxhkgqjfmlgz5a7-postfix-3.9.3/bin/postfix start (code=exited, status=0/SUCCESS)
   Main PID: 7011 (master)
         IP: 0B in, 0B out
         IO: 0B read, 4K written
      Tasks: 3 (limit: 4662)
     Memory: 4.4M (peak: 4.8M)
        CPU: 431ms
     CGroup: /system.slice/postfix.service
             ├─7011 /nix/store/ynccbl3k3p3b3gr38sxhkgqjfmlgz5a7-postfix-3.9.3/libexec/postfix/master -w
             ├─7012 pickup -l -t unix -u
             └─7013 qmgr -l -t unix -u

Apr 19 10:05:28 testsv99 systemd[1]: Starting Postfix mail server...
Apr 19 10:05:29 testsv99 postfix[6997]: /nix/store/ynccbl3k3p3b3gr38sxhkgqjfmlgz5a7-postfix-3.9.3/bin/postconf: warning: /etc/postfix/main.cf: support for parameter "smtp_use_tls" will be removed; instead, specify "smtp_tls_security_level"
Apr 19 10:05:29 testsv99 postfix[6997]: /nix/store/ynccbl3k3p3b3gr38sxhkgqjfmlgz5a7-postfix-3.9.3/bin/postconf: warning: /etc/postfix/main.cf: unused parameter: smtp_tls_CAauth=/etc/pki/tls/certs/
Apr 19 10:05:29 testsv99 postfix[6997]: /nix/store/ynccbl3k3p3b3gr38sxhkgqjfmlgz5a7-postfix-3.9.3/bin/postconf: warning: /etc/postfix/main.cf: unused parameter: inet_protocol=ipv4
Apr 19 10:05:29 testsv99 postfix[7009]: postfix/postlog: starting the Postfix mail system
Apr 19 10:05:29 testsv99 postfix/postfix-script[7009]: starting the Postfix mail system
Apr 19 10:05:29 testsv99 postfix/master[7011]: daemon started -- version 3.9.3, configuration /etc/postfix
Apr 19 10:05:29 testsv99 systemd[1]: Started Postfix mail server.
[testsv99:~ ]# 

 
続いてsudo systemctl status dovecot2コマンドを叩く。Dovecotのサービスのステータスおよびログは以下のとおりである。
こちらも、Active:の行がactive (running)になっている事と、下側に出力されているログにエラーが無い事を確認する。

[testsv99:~ ]# sudo systemctl status dovecot2
● dovecot2.service - Dovecot IMAP/POP3 server
     Loaded: loaded (/etc/systemd/system/dovecot2.service; enabled; preset: ignored)
     Active: active (running) since Sat 2025-04-19 10:05:37 JST; 1min 24s ago
 Invocation: 31859d644fe444019481fd71107cc82b
    Process: 7024 ExecStartPre=/nix/store/8k0h3mw8087bkh9d91z5wf2k1jr03frg-unit-script-dovecot2-pre-start/bin/dovecot2-pre-start (code=exited, status=0/SUCCESS)
   Main PID: 7026 (dovecot)
     Status: "v2.3.21.1 (d492236fa0) running"
         IP: 0B in, 0B out
         IO: 0B read, 4K written
      Tasks: 4 (limit: 4662)
     Memory: 2.4M (peak: 2.9M)
        CPU: 45ms
     CGroup: /system.slice/dovecot2.service
             ├─7026 /nix/store/sabzq7mwpwadrqd02j9lir113rrd4hhh-dovecot-2.3.21.1/sbin/dovecot -F
             ├─7028 dovecot/anvil
             ├─7029 dovecot/log
             └─7030 dovecot/config

Apr 19 10:05:37 testsv99 systemd[1]: Starting Dovecot IMAP/POP3 server...
Apr 19 10:05:37 testsv99 dovecot[7026]: master: Dovecot v2.3.21.1 (d492236fa0) starting up for imap, pop3, imap, pop3, lmtp
Apr 19 10:05:37 testsv99 systemd[1]: Started Dovecot IMAP/POP3 server.
[testsv99:~ ]# 

 


メールサーバの動作確認
PostfixとDovecotの設定追加および変更を終えたところで、クライアント側にてnPOPでテストメールの作成および送受信を行い、クライアント側にメールが正常に届いているか確認する。
nPOPの設定およびテストメールの作成からメールの送信および受信の流れは、前回の記事内の「メールサーバの動作確認」を参照。

クライアント側にてメールの作成と送受信を実施したら、sudo systemctl status postfixコマンドを叩きPostfixのサービスのステータスおよびログを確認する。
Postfixの内部で実行された、メールを処理した際のログで出力されている。
ログに記載されている192.168.3.31は、nPOPを稼働させているクライアント端末のIPアドレスである。

[testsv99:~ ]# sudo systemctl status postfix 
● postfix.service - Postfix mail server
     Loaded: loaded (/etc/systemd/system/postfix.service; enabled; preset: ignored)
     Active: active (running) since Sat 2025-04-19 10:05:29 JST; 10min ago
 Invocation: 41949e5692594be2a826376559860435
    Process: 6931 ExecStart=/nix/store/ynccbl3k3p3b3gr38sxhkgqjfmlgz5a7-postfix-3.9.3/bin/postfix start (code=exited, status=0/SUCCESS)
   Main PID: 7011 (master)
         IP: 1K in, 815B out
         IO: 0B read, 20K written
      Tasks: 4 (limit: 4662)
     Memory: 6.1M (peak: 14M)
        CPU: 578ms
     CGroup: /system.slice/postfix.service
             ├─7011 /nix/store/ynccbl3k3p3b3gr38sxhkgqjfmlgz5a7-postfix-3.9.3/libexec/postfix/master -w
             ├─7012 pickup -l -t unix -u
             ├─7013 qmgr -l -t unix -u
             └─7085 tlsmgr -l -t unix -u

Apr 19 10:10:02 testsv99 postfix/postfix-script[7083]: starting the Postfix mail system
Apr 19 10:10:03 testsv99 postfix/master[7011]: daemon started -- version 3.9.3, configuration /etc/postfix
Apr 19 10:10:03 testsv99 systemd[1]: Started Postfix mail server.
Apr 19 10:13:42 testsv99 postfix/smtpd[7151]: connect from unknown[192.168.3.31]
Apr 19 10:13:43 testsv99 postfix/smtpd[7151]: 679D7261321: client=unknown[192.168.3.31]
Apr 19 10:13:43 testsv99 postfix/cleanup[7156]: 679D7261321: message-id=<20250419101313.B11ECFF0.hechtia@local>
Apr 19 10:13:43 testsv99 postfix/qmgr[7013]: 679D7261321: from=<hechtia@local>, size=484, nrcpt=1 (queue active)
Apr 19 10:13:43 testsv99 postfix/smtpd[7151]: disconnect from unknown[192.168.3.31] helo=1 mail=1 rcpt=1 data=1 rset=1 quit=1 commands=6
Apr 19 10:13:43 testsv99 postfix/local[7157]: 679D7261321: to=<hechtia@local>, relay=local, delay=0.1, delays=0.09/0.01/0/0, dsn=2.0.0, status=sent (delivered to maildir)
Apr 19 10:13:43 testsv99 postfix/qmgr[7013]: 679D7261321: removed
[testsv99:~ ]#

 
続いてsudo systemctl status dovecot2コマンドを叩き、Dovecotのサービスのステータスおよびログを確認。
Dovecotの内部で実行されたメールを処理した際のログが出力されている。

[testsv99:~ ]# sudo systemctl status dovecot2
● dovecot2.service - Dovecot IMAP/POP3 server
     Loaded: loaded (/etc/systemd/system/dovecot2.service; enabled; preset: ignored)
     Active: active (running) since Sat 2025-04-19 10:05:37 JST; 9min ago
 Invocation: 31859d644fe444019481fd71107cc82b
    Process: 7024 ExecStartPre=/nix/store/8k0h3mw8087bkh9d91z5wf2k1jr03frg-unit-script-dovecot2-pre-start/bin/dovecot2-pre-start (code=exited, status=0/SUCCESS)
   Main PID: 7026 (dovecot)
     Status: "v2.3.21.1 (d492236fa0) running"
         IP: 620B in, 2.6K out
         IO: 0B read, 8K written
      Tasks: 6 (limit: 4662)
     Memory: 4M (peak: 23M)
        CPU: 154ms
     CGroup: /system.slice/dovecot2.service
             ├─7026 /nix/store/sabzq7mwpwadrqd02j9lir113rrd4hhh-dovecot-2.3.21.1/sbin/dovecot -F
             ├─7028 dovecot/anvil
             ├─7029 dovecot/log
             ├─7030 dovecot/config
             ├─7153 dovecot/auth
             └─7154 dovecot/stats

Apr 19 10:05:37 testsv99 systemd[1]: Starting Dovecot IMAP/POP3 server...
Apr 19 10:05:37 testsv99 dovecot[7026]: master: Dovecot v2.3.21.1 (d492236fa0) starting up for imap, pop3, imap, pop3, lmtp
Apr 19 10:05:37 testsv99 systemd[1]: Started Dovecot IMAP/POP3 server.
Apr 19 10:13:53 testsv99 dovecot[7029]: pop3-login: Login: user=<hechtia>, method=PLAIN, rip=192.168.3.31, lip=192.168.3.247, mpid=7162, session=<WMsjWRczmsPAqAMf>
Apr 19 10:13:53 testsv99 dovecot[7029]: pop3(hechtia)<7162><WMsjWRczmsPAqAMf>: Disconnected: Logged out top=1/517, retr=2/1123, del=0/2, size=1091
[testsv99:~ ]# 

 

以下の画像は、クライアント端末側でメールの送受信が出来た時に撮ったスクリーンショット。
しかしこれがクライアント端末(HP ProBook 5220m)の最後の勇姿となった。


今回はここまで。
一通り設定を終えたつもりでクライアント端末にてnPOPでメールの送受信のテストを実施したら、/run/dovecot2/auth-loginのアクセス権限が無いというログがsudo systemctl status postfixを実行した際に出力され、nPOPにてメールの送信が出来ない事象が発生した。
上記の手順で実施したとおり、chmodコマンドで/run/dovecot2/auth-loginの書き込み権限を強引に設定する事で対処したが、対処方法をGoogleで検索してもヒットしない為、他のLinuxディストリビューションでは発生しない事象かもしれない。
 


振り返り
全く別の環境でOracle LinuxにPostfixとDovecotを突っ込んでメールサーバの構築をやった事があるからだろう、思っていた以上に早く動作確認の完了まで辿り着く事が出来た。
当記事の作成の為に試験用のクライアント端末として使用したWindows機(HP ProBook 5220m)がついにお亡くなりになった。今年に入り頻繁に再起動を繰り返すようになったが、当記事の作成後、ついにログイン画面に遷移出来なくなった。長い間お疲れ様でした。今のところWindows機が無くても困った事は無いが、どうしても必要になったら中古のSurface Proでも買おうかと思う。
 


参照サイト
https://nixos.org/ Nix & NixOS Declarative builds and deployments
https://nixos.org/manual/nixos/stable/ NixOS Manual
https://search.nixos.org/packages NixOS Search Packages
https://search.nixos.org/options? NixOS Search Options
https://www.postfix.org/ The Postfix Home Page
https://www.dovecot.org/ Dovecot The Secure IMAP server
https://centossrv.com/postfix.shtml メールサーバー構築(Postfix+Dovecot)
https://nakka.com/soft/npop/ nPOP
https://weblabo.oscasierra.net/openssl-gencert-1/ OpenSSL で SSL 自己証明書を発行する手順 - WEB ARCH LABO
https://techblog.ayurina.net/2016/11/08 postfixとdovecotでメールサーバーを作る。ついでに意識高い系SSL設定。
 


NixOS関連の記事
https://debslink.hatenadiary.jp/entry/20250311/1741649715 NixOSの沼に片足を突っ込んだ
https://debslink.hatenadiary.jp/entry/20250316/1742128054 NixOSにFlakeを導入した
https://debslink.hatenadiary.jp/entry/20250320/1742459549 NixOSの環境構築
https://debslink.hatenadiary.jp/entry/20250323/1742731080 NixOSでSFTPサーバの設定
https://debslink.hatenadiary.jp/entry/20250328/1743167901 NixOSでSambaによるファイルサーバの構築
https://debslink.hatenadiary.jp/entry/20250405/1743844940 NixOSでrsyslogの設定
https://debslink.hatenadiary.jp/entry/20250411/1744300480 NixOSでDNSサーバの構築
https://debslink.hatenadiary.jp/entry/20250413/1744551596 NixOSのシステムの再現性の検証
https://debslink.hatenadiary.jp/entry/20250418/1744924524 NixOSでPostfixとDovecotによるメールサーバの構築
https://debslink.hatenadiary.jp/entry/20250419/1745062553 NixOSでPostfixとDovecotによるメールサーバの構築 - SASL認証編
https://debslink.hatenadiary.jp/entry/20250421/1745236668 NixOSのパッケージやOSのアップデートに関するメモ
https://debslink.hatenadiary.jp/entry/20250428/1745795434 NixOSをCLIでインストールした
https://debslink.hatenadiary.jp/entry/20250503/1746235454 NixOSでnginxによるWebサーバの構築
https://debslink.hatenadiary.jp/entry/20250508/1746706416 NixOSでPrometheusとGrafanaによる監視基盤の構築
https://debslink.hatenadiary.jp/entry/20250510/1746884897 NixOSの導入にあたり参考になったサイト
https://debslink.hatenadiary.jp/entry/20250524/1748072722 NixOSを24.11から25.05にアップデートした
https://debslink.hatenadiary.jp/entry/20251214/1765688458 NixOSを25.05から25.11にアップデートした
https://debslink.hatenadiary.jp/entry/20260117/1768615582 Raspberry Pi 4BにNixOSを導入しファイルサーバを構築した
https://debslink.hatenadiary.jp/entry/20260503/1777775392 NixOSで構築したサーバの運用について