以下の内容はhttps://souiunogaii.hatenablog.com/entry/mail-postfix35-dovecot23-installより取得しました。


AlmaLinux9.6+Postfix3.5+Dovecot2.3でメール送受信できるサーバーを構築

※[PR]当ブログの記事の中にはプロモーションが含まれています。

・AlmaLinux9.6 + Postfix3.5 + Dovecot2.3 でメールの送受信ができるサーバーを構築する方法を知りたい。
・具体的な手順を分かりやすく教えてほしい。

こういった疑問に答えます。

本記事の内容

  1. AlmaLinux9.6+Postfix3.5+Dovecot2.3でメール送受信できるサーバーを構築する手順

サトナカ (@souiunogaii)

この記事を書いている私は、某SIerに勤務しながら、
WEB系エンジニア・インフラエンジニアに憧れて、プログラミングおよびインフラ技術の勉強をしています。

こういった私が、解説していきます。

私が実機で試したコマンドや画像を載せて書いています。
記事の信頼性担保に繋がると思います。

前回の記事

souiunogaii.hatenablog.com

DNSサーバーにMXレコードの追加

/var/named/blue-planet.internal
$TTL      86400
@         IN       SOA     b-bidns01.blue-planet.internal.  root.blue-planet.internal.(
                                                 2025083005 ; Serial
                                                 28800      ; Refresh
                                                 14400      ; Retry
                                                 3600000    ; Expire
                                                 86400 )    ; Minimum
          IN NS b-bidns01.blue-planet.internal.
          IN NS a-bidns02.blue-planet.internal.
@         IN MX 10 a-email01.blue-planet.internal.  ←★★★追加
a-email01 IN A 192.168.100.121
a-bidns02 IN A 192.168.100.128
b-bidns01 IN A 192.168.100.132

確認

[root@a-email01 postfix]# host -t mx blue-planet.internal
blue-planet.internal mail is handled by 10 a-email01.blue-planet.internal.

dovecot2.3のインストール

dnf install dovecot -y
[root@a-email01 ~]# dnf install dovecot -y
メタデータの期限切れの最終確認: 0:49:53 前の 20250831231313秒 に実施しました。
依存関係が解決しました。
====================================================================================================
 パッケージ          Arch         バージョン                                  リポジトリー    サイズ
====================================================================================================
インストール:
 dovecot             x86_64       1:2.3.16-15.el9                             appstream       4.7 M
依存関係のインストール:
 clucene-core        x86_64       2.3.3.4-42.20130812.e8e3d20git.el9          appstream       585 k
 libexttextcat       x86_64       3.4.5-11.el9                                appstream       209 k

トランザクションの概要
====================================================================================================
インストール  3 パッケージ

ダウンロードサイズの合計: 5.5 M
インストール後のサイズ: 20 M
パッケージのダウンロード:
(1/3): libexttextcat-3.4.5-11.el9.x86_64.rpm                        838 kB/s | 209 kB     00:00
(2/3): clucene-core-2.3.3.4-42.20130812.e8e3d20git.el9.x86_64.rpm   1.0 MB/s | 585 kB     00:00
(3/3): dovecot-2.3.16-15.el9.x86_64.rpm                             6.0 MB/s | 4.7 MB     00:00
----------------------------------------------------------------------------------------------------
合計                                                                3.8 MB/s | 5.5 MB     00:01
トランザクションを確認しています
トランザクションの確認に成功しました。
トランザクションをテストしています
トランザクションのテストに成功しました。
トランザクションを実行しています
  準備中           :                                                                            1/1
  インストール中   : libexttextcat-3.4.5-11.el9.x86_64                                          1/3
  インストール中   : clucene-core-2.3.3.4-42.20130812.e8e3d20git.el9.x86_64                     2/3
  scriptletの実行中: dovecot-1:2.3.16-15.el9.x86_64                                             3/3
  インストール中   : dovecot-1:2.3.16-15.el9.x86_64                                             3/3
  scriptletの実行中: dovecot-1:2.3.16-15.el9.x86_64                                             3/3
  検証中           : clucene-core-2.3.3.4-42.20130812.e8e3d20git.el9.x86_64                     1/3
  検証中           : dovecot-1:2.3.16-15.el9.x86_64                                             2/3
  検証中           : libexttextcat-3.4.5-11.el9.x86_64                                          3/3

インストール済み:
  clucene-core-2.3.3.4-42.20130812.e8e3d20git.el9.x86_64       dovecot-1:2.3.16-15.el9.x86_64
  libexttextcat-3.4.5-11.el9.x86_64

完了しました!

サービス開始

systemctl start dovecot
[root@a-email01 ~]# systemctl start dovecot
[root@a-email01 ~]# systemctl status dovecot
● dovecot.service - Dovecot IMAP/POP3 email server
     Loaded: loaded (/usr/lib/systemd/system/dovecot.service; disabled; preset: disabled)
     Active: active (running) since Mon 2025-09-01 00:03:27 JST; 6s ago
       Docs: man:dovecot(1)
             https://doc.dovecot.org/
    Process: 4018 ExecStartPre=/usr/libexec/dovecot/prestartscript (code=exited, status=0/SUCCESS)
   Main PID: 4024 (dovecot)
     Status: "v2.3.16 (7e2e900c1a) running"
      Tasks: 4 (limit: 11066)
     Memory: 5.2M
        CPU: 52ms
     CGroup: /system.slice/dovecot.service
             tq4024 /usr/sbin/dovecot -F
             tq4025 dovecot/anvil
             tq4026 dovecot/log
             mq4027 dovecot/config

 901 00:03:27 a-email01 systemd[1]: Starting Dovecot IMAP/POP3 email server...
 901 00:03:27 a-email01 dovecot[4024]: master: Dovecot v2.3.16 (7e2e900c1a) starting up for imap>
 901 00:03:27 a-email01 systemd[1]: Started Dovecot IMAP/POP3 email server.

自動起動の設定

systemctl enable dovecot
systemctl is-enabled dovecot
[root@a-email01 ~]# systemctl enable dovecot
Created symlink /etc/systemd/system/multi-user.target.wants/dovecot.service → /usr/lib/systemd/system/dovecot.service.
[root@a-email01 ~]# systemctl is-enabled dovecot
enabled

dovecot.confの編集

/etc/dovecot/dovecot.conf
[root@a-email01 ~]# cd /etc/dovecot
[root@a-email01 dovecot]# ll
合計 12
drwxr-xr-x 2 root root 4096  91 00:03 conf.d
-rw-r--r-- 1 root root 4333  86  2021 dovecot.conf
[root@a-email01 dovecot]# cp -p /etc/dovecot/dovecot.conf /etc/dovecot/dovecot.conf_original
[root@a-email01 dovecot]# vi /etc/dovecot/dovecot.conf
     23 # Protocols we want to be serving.
     24 protocols = imap pop3  ←★★★変更

10-auth.confの編集

/etc/dovecot/conf.d/10-auth.conf
[root@a-email01 dovecot]# cp /etc/dovecot/conf.d/10-auth.conf /etc/dovecot/conf.d/10-auth.conf_original
[root@a-email01 dovecot]# vi /etc/dovecot/conf.d/10-auth.conf
      5 # Disable LOGIN command and all other plaintext authentications unless
      6 # SSL/TLS is used (LOGINDISABLED capability). Note that if the remote IP
      7 # matches the local IP (ie. you're connecting from the same computer), the
      8 # connection is considered secure and plaintext authentication is allowed.
      9 # See also ssl=required setting.
     10 disable_plaintext_auth = no  ←★★★変更


  (中略)

     96 # Space separated list of wanted authentication mechanisms:
     97 #   plain login digest-md5 cram-md5 ntlm rpa apop anonymous gssapi otp
     98 #   gss-spnego
     99 # NOTE: See also disable_plaintext_auth setting.
    100 auth_mechanisms = plain login  ←★★★変更

10-mail.confの編集

/etc/dovecot/conf.d/10-mail.conf
[root@a-email01 dovecot]# cp -p /etc/dovecot/conf.d/10-mail.conf /etc/dovecot/conf.d/10-mail.conf_original
[root@a-email01 dovecot]# vi /etc/dovecot/conf.d/10-mail.conf
     22 # See doc/wiki/Variables.txt for full list. Some examples:
     23 #
     24 #   mail_location = maildir:~/Maildir
     25 #   mail_location = mbox:~/mail:INBOX=/var/mail/%u
     26 #   mail_location = mbox:/var/mail/%d/%1n/%n:INDEX=/var/indexes/%d/%1n/%n
     27 #
     28 # <doc/wiki/MailLocation.txt>
     29 #
     30 mail_location = maildir:~/Maildir  ←★★★変更

10-ssl.confの編集

/etc/dovecot/conf.d/10-ssl.conf
[root@a-email01 dovecot]# cp -p /etc/dovecot/conf.d/10-ssl.conf /etc/dovecot/conf.d/10-ssl.conf_original
[root@a-email01 dovecot]# vi /etc/dovecot/conf.d/10-ssl.conf
      1 ##
      2 ## SSL settings
      3 ##
      4
      5 # SSL/TLS support: yes, no, required. <doc/wiki/SSL.txt>
      6 # disable plain pop3 and imap, allowed are only pop3+TLS, pop3s, imap+TLS and imaps
      7 # plain imap and pop3 are still allowed for local connections
      8 ssl = no  ←★★★変更

10-master.confの編集

/etc/dovecot/conf.d/10-master.conf
[root@a-email01 dovecot]# cp -p /etc/dovecot/conf.d/10-master.conf /etc/dovecot/conf.d/10-master.conf_original
[root@a-email01 dovecot]# vi /etc/dovecot/conf.d/10-master.conf
    106   # Postfix smtp-auth
    107   unix_listener /var/spool/postfix/private/auth {  ←★★★コメント解除
    108     mode = 0666  ←★★★変更
    109     user = postfix  ←★★★変更
    110     group = postfix  ←★★★変更
    111   }  ←★★★コメント解除

dovecotを再起動して設定を反映

[root@a-email01 dovecot]# doveconf -n
[root@a-email01 dovecot]# systemctl restart dovecot

110番(POP3)と143番(IMAP4)ポートがLISTENであることの確認

netstat -nat
[root@a-email01 dovecot]# netstat -nat
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:110             0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:143             0.0.0.0:*               LISTEN
tcp        0      0 127.0.0.1:199           0.0.0.0:*               LISTEN
tcp        0    268 192.168.100.121:22      192.168.100.101:63144   ESTABLISHED
tcp        1      0 192.168.100.121:36772   192.168.100.131:514     CLOSE_WAIT
tcp        0      0 192.168.100.121:22      192.168.100.101:63164   ESTABLISHED
tcp6       0      0 :::22                   :::*                    LISTEN
tcp6       0      0 :::110                  :::*                    LISTEN
tcp6       0      0 :::143                  :::*                    LISTEN

Postfixのmain.cfの編集

/etc/postfix/main.cf
    124 # The inet_interfaces parameter specifies the network interface
    125 # addresses that this mail system receives mail on.  By default,
    126 # the software claims all active interfaces on the machine. The
    127 # parameter also controls delivery of mail to user@[ip.address].
    128 #
    129 # See also the proxy_interfaces parameter, for network addresses that
    130 # are forwarded to us via a proxy or network address translator.
    131 #
    132 # Note: you need to stop/start Postfix when this parameter changes.
    133 #
    134 inet_interfaces = all  ←★★★コメント解除
    135 #inet_interfaces = $myhostname
    136 #inet_interfaces = $myhostname, localhost
    137 #inet_interfaces = localhost  ←★★★コメントで無効化

  (中略)

    183 # See also below, section "REJECTING MAIL FOR UNKNOWN LOCAL USERS".
    184 #
    185 #mydestination = $myhostname, localhost.$mydomain, localhost  ←★★★コメントで無効化
    186 mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain  ←★★★コメント解除
    187 #mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain,
    188 #       mail.$mydomain, www.$mydomain, ftp.$mydomain

  (中略)

    432 # DELIVERY TO MAILBOX
    433 #
    434 # The home_mailbox parameter specifies the optional pathname of a
    435 # mailbox file relative to a user's home directory. The default
    436 # mailbox file is /var/spool/mail/user or /var/mail/user.  Specify
    437 # "Maildir/" for qmail-style delivery (the / is required).
    438 #
    439 #home_mailbox = Mailbox
    440 home_mailbox = Maildir/  ←★★★コメント解除

  (中略)

    593 #smtpd_banner = $myhostname ESMTP $mail_name
    594 #smtpd_banner = $myhostname ESMTP $mail_name ($mail_version)
    595 smtpd_banner = $myhostname ESMTP

  (中略)

    744 ### SMTP-AUTH  ←★★★追加
    745 smtpd_sasl_auth_enable = yes  ←★★★追加
    746 smtpd_sasl_type = dovecot  ←★★★追加
    747 smtpd_sasl_path = private/auth  ←★★★追加
    748 broken_sasl_auth_clients = yes  ←★★★追加
    749 smtpd_recipient_restrictions = permit_mynetworks permit_sasl_authenticated reject_unauth_des        tination  ←★★★追加
    750

変更後の確認

[root@a-email01 ~]# postconf -n
[root@a-email01 ~]# postfix check

Postfixのmaster.cfの編集

/etc/postfix/master.cf
      8 # ==========================================================================
      9 # service type  private unpriv  chroot  wakeup  maxproc command + args
     10 #               (yes)   (yes)   (no)    (never) (100)
     11 # ==========================================================================
     12 smtp      inet  n       -       n       -       -       smtpd
     13 #smtp      inet  n       -       n       -       1       postscreen
     14 #smtpd     pass  -       -       n       -       -       smtpd
     15 #dnsblog   unix  -       -       n       -       0       dnsblog
     16 #tlsproxy  unix  -       -       n       -       0       tlsproxy
     17 submission inet n       -       n       -       -       smtpd  ←★★★コメント解除

Postfixを再起動して変更を反映

[root@a-email01 ~]# systemctl restart postfix

587番(submission)ポートがLISTENであることを確認

[root@a-email01 ~]# netstat -nat
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:25              0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:110             0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:143             0.0.0.0:*               LISTEN
tcp        0      0 127.0.0.1:199           0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:587             0.0.0.0:*               LISTEN
tcp        0      0 192.168.100.121:22      192.168.100.101:63144   ESTABLISHED
tcp        1      0 192.168.100.121:46386   192.168.100.131:514     CLOSE_WAIT
tcp        0      0 192.168.100.121:22      192.168.100.101:63164   ESTABLISHED
tcp6       0      0 :::22                   :::*                    LISTEN
tcp6       0      0 :::110                  :::*                    LISTEN
tcp6       0      0 :::143                  :::*                    LISTEN

firewalldの許可設定を追加

smtp,smtp-submission,pop3,imap
[root@a-email01 ~]# firewall-cmd --zone=home --add-service={smtp,smtp-submission,pop3,imap} --permanent
success
[root@a-email01 ~]# firewall-cmd --reload
success

メールソフトで確認

POP3SMTP

IMAPSMTP-submission




以上の内容はhttps://souiunogaii.hatenablog.com/entry/mail-postfix35-dovecot23-installより取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14