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


AlmaLinux9.6とPostfix3.5を使ってメール送信できるサーバーを構築

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

・AlmaLinux9.6 にPostfix3.5をインストールしてメール送信する方法を知りたい。
・具体的な手順を分かりやすく教えてほしい。

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

本記事の内容

  1. AlmaLinux9.6とPostfix3.5を使ってメール送信できるサーバーを構築する手順

サトナカ (@souiunogaii)

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

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

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

AlmaLinux9.6とPostfix3.5を使ってメール送信できるサーバーを構築

Postfixのインストール

dnf install postfix -y
[root@a-email01 ~]# dnf install postfix -y
メタデータの期限切れの最終確認: 0:12:25 前の 20250831231313秒 に実施しました。
依存関係が解決しました。
====================================================================================================
 パッケージ           アーキテクチャー    バージョン                   リポジトリー           サイズ
====================================================================================================
インストール:
 postfix              x86_64              2:3.5.25-1.el9               appstream              1.5 M

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

ダウンロードサイズの合計: 1.5 M
インストール後のサイズ: 4.4 M
パッケージのダウンロード:
postfix-3.5.25-1.el9.x86_64.rpm                                     6.0 MB/s | 1.5 MB     00:00
----------------------------------------------------------------------------------------------------
合計                                                                1.8 MB/s | 1.5 MB     00:00
トランザクションを確認しています
トランザクションの確認に成功しました。
トランザクションをテストしています
トランザクションのテストに成功しました。
トランザクションを実行しています
  準備中           :                                                                            1/1
  scriptletの実行中: postfix-2:3.5.25-1.el9.x86_64                                              1/1
  インストール中   : postfix-2:3.5.25-1.el9.x86_64                                              1/1
  scriptletの実行中: postfix-2:3.5.25-1.el9.x86_64                                              1/1
  検証中           : postfix-2:3.5.25-1.el9.x86_64                                              1/1

インストール済み:
  postfix-2:3.5.25-1.el9.x86_64

完了しました!
[root@a-email01 ~]# dnf list installed | grep postfix
postfix.x86_64                                 2:3.5.25-1.el9                   @appstream

デフォルト設定の確認

[root@a-email01 ~]# postconf -n
alias_database = hash:/etc/aliases
alias_maps = hash:/etc/aliases
command_directory = /usr/sbin
compatibility_level = 2
daemon_directory = /usr/libexec/postfix
data_directory = /var/lib/postfix
debug_peer_level = 2
debugger_command = PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin ddd $daemon_directory/$process_name $process_id & sleep 5
html_directory = no
inet_interfaces = localhost
inet_protocols = all
mail_owner = postfix
mailq_path = /usr/bin/mailq.postfix
manpage_directory = /usr/share/man
meta_directory = /etc/postfix
mydestination = $myhostname, localhost.$mydomain, localhost
newaliases_path = /usr/bin/newaliases.postfix
queue_directory = /var/spool/postfix
readme_directory = /usr/share/doc/postfix/README_FILES
sample_directory = /usr/share/doc/postfix/samples
sendmail_path = /usr/sbin/sendmail.postfix
setgid_group = postdrop
shlib_directory = /usr/lib64/postfix
smtp_tls_CAfile = /etc/pki/tls/certs/ca-bundle.crt
smtp_tls_CApath = /etc/pki/tls/certs
smtp_tls_security_level = may
smtpd_tls_cert_file = /etc/pki/tls/certs/postfix.pem
smtpd_tls_key_file = /etc/pki/tls/private/postfix.key
smtpd_tls_security_level = may
unknown_local_recipient_reject_code = 550
[root@a-email01 ~]# cd /etc/postfix
[root@a-email01 postfix]# ll
合計 220
-rw-r--r-- 1 root root 21111  98  2019 access
-rw-r--r-- 1 root root 13194  64  2018 canonical
-rw-r--r-- 1 root root    60 103  2024 dynamicmaps.cf
drwxr-xr-x 2 root root     6 103  2024 dynamicmaps.cf.d
-rw-r--r-- 1 root root 10221  917  2016 generic
-rw-r--r-- 1 root root 23802 109  2016 header_checks
-rw-r--r-- 1 root root 29369 103  2024 main.cf
-rw-r--r-- 1 root root 29130 103  2024 main.cf.proto
-rw-r--r-- 1 root root  6372 103  2024 master.cf
-rw-r--r-- 1 root root  6372 103  2024 master.cf.proto
-rw-r--r-- 1 root root 20163 103  2024 postfix-files
drwxr-xr-x 2 root root     6 103  2024 postfix-files.d
-rw-r--r-- 1 root root  6929  214  2016 relocated
-rw-r--r-- 1 root root 13436  111  2020 transport
-rw-r--r-- 1 root root 13963  64  2018 virtual

main.cfの編集

/etc/postfix/main.cf
[root@a-email01 postfix]# cp -p /etc/postfix/main.cf /etc/postfix/main.cf_original
[root@a-email01 postfix]# vi /etc/postfix/main.cf
     87 # INTERNET HOST AND DOMAIN NAMES
     88 #
     89 # The myhostname parameter specifies the internet hostname of this
     90 # mail system. The default is to use the fully-qualified domain name
     91 # from gethostname(). $myhostname is used as a default value for many
     92 # other configuration parameters.
     93 #
     94 #myhostname = host.domain.tld
     95 #myhostname = virtual.domain.tld
     96 myhostname = a-email01.blue-planet.internal   ←★★★変更


  (中略)


     98 # The mydomain parameter specifies the local internet domain name.
     99 # The default is to use $myhostname minus the first component.
    100 # $mydomain is used as a default value for many other configuration
    101 # parameters.
    102 #
    103 #mydomain = domain.tld
    104 mydomain = blue-planet.internal   ←★★★変更


  (中略)


    139 # Enable IPv4, and IPv6 if supported
    140 inet_protocols = ipv4   ←★★★変更

確認

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

サービス再起動

systemctl restart postfix
[root@a-email01 postfix]# systemctl restart postfix
[root@a-email01 postfix]# systemctl status postfix
● postfix.service - Postfix Mail Transport Agent
     Loaded: loaded (/usr/lib/systemd/system/postfix.service; disabled; preset: disabled)
     Active: active (running) since Sun 2025-08-31 23:35:15 JST; 7s ago
    Process: 3065 ExecStartPre=/usr/sbin/restorecon -R /var/spool/postfix/pid (code=exited, status=>
    Process: 3066 ExecStartPre=/usr/libexec/postfix/aliasesdb (code=exited, status=0/SUCCESS)
    Process: 3070 ExecStartPre=/usr/libexec/postfix/chroot-update (code=exited, status=0/SUCCESS)
    Process: 3071 ExecStart=/usr/sbin/postfix start (code=exited, status=0/SUCCESS)
   Main PID: 3139 (master)
      Tasks: 3 (limit: 11066)
     Memory: 4.4M
        CPU: 315ms
     CGroup: /system.slice/postfix.service
             tq3139 /usr/libexec/postfix/master -w
             tq3140 pickup -l -t unix -u
             mq3141 qmgr -l -t unix -u

 831 23:35:15 a-email01 systemd[1]: Starting Postfix Mail Transport Agent...
 831 23:35:15 a-email01 postfix/postfix-script[3137]: starting the Postfix mail system
 831 23:35:15 a-email01 postfix/master[3139]: daemon started -- version 3.5.25, configuration /e>
 831 23:35:15 a-email01 systemd[1]: Started Postfix Mail Transport Agent.

自動起動の設定

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

送信テスト

telnetインストール

dnf install telnet -y
[root@a-email01 postfix]# dnf install telnet -y
メタデータの期限切れの最終確認: 0:22:53 前の 20250831231313秒 に実施しました。
依存関係が解決しました。
====================================================================================================
 パッケージ          アーキテクチャー    バージョン                    リポジトリー           サイズ
====================================================================================================
インストール:
 telnet              x86_64              1:0.17-85.el9                 appstream               63 k

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

ダウンロードサイズの合計: 63 k
インストール後のサイズ: 121 k
パッケージのダウンロード:
telnet-0.17-85.el9.x86_64.rpm                                       697 kB/s |  63 kB     00:00
----------------------------------------------------------------------------------------------------
合計                                                                 93 kB/s |  63 kB     00:00
トランザクションを確認しています
トランザクションの確認に成功しました。
トランザクションをテストしています
トランザクションのテストに成功しました。
トランザクションを実行しています
  準備中           :                                                                            1/1
  インストール中   : telnet-1:0.17-85.el9.x86_64                                                1/1
  scriptletの実行中: telnet-1:0.17-85.el9.x86_64                                                1/1
  検証中           : telnet-1:0.17-85.el9.x86_64                                                1/1

インストール済み:
  telnet-1:0.17-85.el9.x86_64

完了しました!

コマンドで送信テスト

 telnet localhost 25
[root@a-email01 postfix]# telnet localhost 25
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 a-email01.blue-planet.internal ESMTP Postfix
helo localhost   ←★★★heloで応答
250 a-email01.blue-planet.internal
mail from:root@blue-planet.internal  ←★★★From送信者アドレス
250 2.1.0 Ok
rcpt to:satonaka@blue-planet.com  ←★★★To宛先アドレス
250 2.1.5 Ok
data      ←★★★dataで本文の開始
354 End data with <CR><LF>.<CR><LF>
test mail ←★★★本文を入力
.   ←★★★ピリオドで終了
250 2.0.0 Ok: queued as 9C796203BC08
quit  ←★★★quitで切断
221 2.0.0 Bye
Connection closed by foreign host.

ログ確認

/var/log/maillog
Aug 31 23:41:25 a-email01 postfix/cleanup[3319]: 9C796203BC08: message-id=<20250831144118.9C796203BC08@a-email01.blue-planet.internal>
Aug 31 23:41:25 a-email01 postfix/qmgr[3141]: 9C796203BC08: from=<root@blue-planet.internal>, size=360, nrcpt=1 (queue active)
Aug 31 23:41:25 a-email01 postfix/smtp[3320]: 9C796203BC08: to=<satonaka@blue-planet.com>, relay=blue-planet.com[XXX.XXX.XXX.XXX]:25, delay=27, delays=27/0.02/0.08/0.11, dsn=2.0.0, status=sent (250 2.0.0 Ok: queued as D5980497588)
Aug 31 23:41:25 a-email01 postfix/qmgr[3141]: 9C796203BC08: removed
Aug 31 23:41:30 a-email01 postfix/smtpd[3314]: disconnect from localhost[127.0.0.1] helo=1 mail=1 rcpt=1 data=1 quit=1 commands=5

メールソフトで受信確認




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

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