#author("2025-03-17T11:37:15+09:00;2025-03-17T10:54:43+09:00","default:tanopro","tanopro")
#author("2025-03-21T19:32:30+09:00;2025-03-17T10:54:43+09:00","default:tanopro","tanopro")
#html{{
<h1 style="color: red; background-color: #FFFFCC; padding: 20px;">
Postfix(ポストフィックス)
</h1>

<div class="alert alert-warning" role="alert">
Postfix(ポストフィックス)は、メールの転送を目的としたオープンソースのメールサーバソフトウェアです。<br>
メール転送エージェント(MTA)の一種で、Unix系のOSに対応しています。
</div>
}}

//----------------------------------------
#contents
//----------------------------------------

//----------------------------------------
// 用語の定義
* Postfix(ポストフィックス)とは? [#definition]
メール送信用の[[メールサーバー]]の1つ。
Postfixにはメールの受信機能はありません。
メール受信のために、[[Dovecot]]と一緒によく使われています。

- Postfix - Google 検索
https://www.google.co.jp/search?q=Postfix

- Postfix - Wikipedia
https://ja.wikipedia.org/wiki/Postfix
>Postfix(ポストフィックス)は自由ソフトウェア・オープンソースソフトウェアのメール転送エージェント(MTA)である。
先行して開発されていたSendmailとの操作上の互換性を確保しつつ、管理・設定が容易で、高速・安全であることを指向して開発されている

** 公式サイト [#k892ae55]
- The Postfix Home Page
https://www.postfix.org/

** 非公式サイト [#q7b608c3]
- GitHub - vdukhovni/postfix: Postfix MTA by Wietse Venema
https://github.com/vdukhovni/postfix

- Postfixのぺーじ
https://postfix-jp.info/

//----------------------------------------
* インストール [#m0965a48]
Ubuntu 24.04 LTSにPostfixをインストールするメモ。


** 参考 [#q114b502]
- Postfix インストール - Google 検索
https://www.google.co.jp/search?q=Postfix+%E3%82%A4%E3%83%B3%E3%82%B9%E3%83%88%E3%83%BC%E3%83%AB


** aptコマンドでインストールできるバージョンの確認方法 [#nc59ad00]
Ubuntu 24.04 LTS において ''apt'' コマンドでインストールできる Postfix のバージョンを確認するには、以下の方法があります。

*** 方法1: ''apt show'' コマンドを使用する [#y79f817b]
 apt show postfix
このコマンドを実行すると、''Version:'' の行にインストール可能なバージョンが表示されます。

出力例
 Package: postfix
 Version: 3.8.6-1build2
 Priority: optional
 Section: mail
 Origin: Ubuntu
 Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
 Original-Maintainer: LaMont Jones <lamont@debian.org>
 Bugs: https://bugs.launchpad.net/ubuntu/+filebug
 Installed-Size: 4,195 kB
 Provides: default-mta, mail-transport-agent
 Pre-Depends: init-system-helpers (>= 1.54~)
 Depends: adduser (>= 3.48), cpio, dpkg (>= 1.8.3), e2fsprogs, netbase, ssl-cert, debconf (>= 0.5) | debconf-2.0, libc6 (>= 2.34), libdb5.3t64, libicu74 (>= 74.1-1~), libnsl2 (>= 1.0), libsasl2-2 (>= 2.1.28+dfsg1), libssl3t64 (>= 3.0.0)
 Recommends: ca-certificates, python3
 Suggests: libsasl2-modules | dovecot-common, mail-reader, postfix-cdb, postfix-doc, postfix-ldap, postfix-lmdb, postfix-mta-sts-resolver, postfix-mysql, postfix-pcre, postfix-pgsql, postfix-sqlite, procmail, resolvconf, sasl2-bin | dovecot-common, ufw
 Conflicts: mail-transport-agent, smail
 Replaces: mail-transport-agent
 Homepage: https://www.postfix.org
 Task: mail-server
 Download-Size: 1,254 kB
 APT-Sources: http://jp.archive.ubuntu.com/ubuntu noble/main amd64 Packages
 Description: High-performance mail transport agent
  Postfix is Wietse Venema's mail transport agent that started life as an
  alternative to the widely-used Sendmail program.  Postfix attempts to
  be fast, easy to administer, and secure, while at the same time being
  sendmail compatible enough to not upset existing users. Thus, the outside
  has a sendmail-ish flavor, but the inside is completely different.

*** 方法2: ''apt-cache policy'' コマンドを使用する [#q176b3de]
 apt-cache policy postfix
このコマンドを実行すると、以下のような出力が得られます。

出力例
 postfix:
   Installed: (none)
   Candidate: 3.8.6-1build2
   Version table:
      3.8.6-1build2 500
         500 http://jp.archive.ubuntu.com/ubuntu noble/main amd64 Packages

''Candidate:'' に表示されているバージョンが、現在 ''apt'' でインストール可能なバージョンです。

*** 方法3: ''apt list'' コマンドを使用する [#i4d00860]
 apt list postfix
このコマンドを実行すると、次のような出力が得られます。

出力例
 Listing... Done
 postfix/noble 3.8.6-1build2 amd64
ここで ''3.8.6-1build2'' の部分が、インストールできるバージョンです。

*** 方法4: ''apt-cache madison'' コマンドを使用する [#t5c5df38]
 apt-cache madison postfix
このコマンドでは、利用可能なすべてのバージョンが表示されます。

出力例
 postfix | 3.8.6-1build2 | http://jp.archive.ubuntu.com/ubuntu noble/main amd64 Packages

---

これらの方法で、Ubuntu 24.04 LTS で利用可能な Postfix のバージョンを確認できます。


//----------------------------------------
* Ubuntu 24.04 に Postfix をインストールする方法 [#q1ed0ce5]

Ubuntu 24.04 で ''apt'' コマンドを使用して Postfix をインストールする方法を説明します。

** 1. システムの更新 [#d7920d16]
まず、パッケージリストを最新の状態に更新します。
 sudo apt update
 sudo apt upgrade -y

** 2. Postfix のインストール [#pe72ca01]
次に、Postfix をインストールします。
 sudo apt install -y postfix

出力例
 $ sudo apt install postfix

 Reading package lists... Done
 Building dependency tree... Done
 Reading state information... Done
 The following additional packages will be installed:
   libnsl2
 Suggested packages:
   mail-reader postfix-cdb postfix-doc postfix-ldap postfix-lmdb
   postfix-mta-sts-resolver postfix-mysql postfix-pcre postfix-pgsql postfix-sqlite
   procmail sasl2-bin | dovecot-common
 The following NEW packages will be installed:
   libnsl2 postfix
 0 upgraded, 2 newly installed, 0 to remove and 1 not upgraded.
 Need to get 1,296 kB of archives.
 After this operation, 4,321 kB of additional disk space will be used.
 Do you want to continue? [Y/n] →Yと入力する。


** 3. インストール時の設定 [#qc9d3d11]
Postfix のインストール中に、Postfix Configuration のウィザードが表示されます。
以下のような設定オプションが選択できます。

*** メイン設定タイプの選択 [#db097c4d]
「Postfix Configuration」のプロンプトが表示されたら、以下のオプションから適切なものを選択します。

- Internet Site(インターネット向けのメールサーバー)
- Smarthost(別のSMTPサーバーをリレーとして利用)
- Local only(ローカルネットワーク内のみで使用)

通常のメールサーバーとして使用する場合は、''Internet Site'' を選択します。

#ref(./Postfix_Package_configuration_Q1.png,800x)

~
-操作方法
-- OK:大文字の「O」を入力する ''「Shift」+「o」''
-- Cancel:大文字の「C」を入力する ''「Shift」+「c」''
-- 矢印キー「↑」、「↓」で選択肢を移動する
-- TABキーで選択肢を移動する
-- スペースキーで選択した状態にする
-- Enterキーで決定する
などで、この画面をキーボードで操作できます。

*** メール送信元の設定 [#z86870e2]
次に、System mail name(システムのメール名)を設定します。  
デフォルトではホスト名が設定されますが、適宜 ''example.com'' などのドメイン名を指定してください。

#ref(./Postfix_Package_configuration_Q2.png,800x)

~
「myname @ mydomain.net」というメールアドレスを使いたい場合、「System mail name」の欄には「mydomain.net」と入力します。

** 4. Postfix の設定確認 [#p13d6ef0]
Postfix の設定ファイルは ''/etc/postfix/main.cf'' です。
インストール後、設定を確認し、必要に応じて修正してください。

*** Postfixの設定ファイルのバックアップ [#wc319510]
''main.cf'' を編集する前にバックアップを取っておきます。
万が一、設定ミスが発生した場合でも、バックアップから元の設定に戻すことができます。

- バックアップの方法
以下のコマンドを実行すると、現在の ''main.cf'' のバックアップを作成できます。
 sudo cp /etc/postfix/main.cf /etc/postfix/main.cf.bak
これにより、''/etc/postfix/main.cf.bak'' というバックアップファイルが作成されます。
以下のコマンドでバックアップファイルが作成されたか目視確認できます。
 ls -l /etc/postfix

- バックアップをリストア(復元)する方法
もし設定を変更した後に問題が発生した場合は、以下のコマンドでバックアップを元に戻せます。
 sudo cp /etc/postfix/main.cf.bak /etc/postfix/main.cf
その後、Postfix を再起動して変更を適用します。
 sudo systemctl restart postfix

- 変更内容を確認する方法
''diff'' コマンドを使用すると、元の設定と編集後の設定の違いを確認できます。
 diff /etc/postfix/main.cf /etc/postfix/main.cf.bak


*** Postfixの設定ファイルの編集 [#gd03d68b]
 sudo nano /etc/postfix/main.cf

以下の項目を確認・編集してください。

 ini
 
 myhostname = mail.example.com  # サーバーのFQDN
 myhostname = mail.example.com  # SMTPサーバーのFQDN(ホスト名+ドメイン名)
 mydomain = example.com
 myorigin = $mydomain
 inet_interfaces = all

設定を変更した場合は、Postfix を再起動します。
 sudo systemctl restart postfix

** 5. Postfix の動作確認 [#u14d5d3e]
インストール後、Postfix のステータスを確認して、正常に動作していることを確認します。
 sudo systemctl status postfix

''Active: active (running)'' という表示が出ていれば正常に動作しています。

また、ポート 25 が開いているかを確認するには、以下のコマンドを使用します。
 sudo netstat -tulnp | grep :25

または、
 sudo ss -tulnp | grep :25

** 6. 簡単なメール送信テスト [#kdc04e8a]
ローカルでメールを送信して動作を確認できます。
 echo "Postfix テストメール" | mail -s "テストメール" ユーザー名@example.com

** 7. Postfix のログ確認 [#ce4a8bc1]
メールの送受信で問題が発生した場合は、ログを確認します。
 sudo journalctl -u postfix --no-pager
または、
 sudo tail -f /var/log/mail.log

以上で、Ubuntu 24.04 に Postfix をインストールする手順は完了です。





//----------------------------------------
// *Amazon [#amazon]
#html{{

}}


//----------------------------------------
* 関連 [#m39471c0]
//----------------------------------------

-[[メールサーバー]]
-[[Dovecot]]

トップ   編集 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS