私は、From ヘッダーの正規化を許可するアドレス書き換え用に構成された postfix インスタンスを持っています。
現在の(必要な?)構成
関連する構成は次のとおりです。
# Basic conf
myhostname = hostname.example.test
mydomain = example.test
mynetworks = 127.0.0.0/8,1.2.3.4/32
myorigin = $mydomain
mydestination =
# Rewrite options
append_at_myorigin = yes
local_header_rewrite_clients = permit_mynetworks
sender_canonical_classes = envelope_sender, header_sender
sender_canonical_maps = hash:/etc/postfix/sender_canonical
recipient_canonical_classes = envelope_recipient, header_recipient
recipient_canonical_maps = hash:/etc/postfix/recipient_canonical
# restrictions (redacted for readability)
smtpd_sender_restrictions = permit_mynetworks, reject_non_fqdn_sender, permit
望ましい結果
私が達成したいのは、次のことです。
- 127.0.0.1からメールを受信すると、(つまりroot@$hostname)
From: root
に書き換えられます。From: [email protected]
- 1.2.3.4からメールを受信すると、(つまりroot@$mydomain)
From: root
に書き換えられます。From: [email protected]
- 他の人からメールを受信した場合、メールは
From: root
拒否されます(制限がreject_non_fqdn_sender
適用されているため)
問題
変数は$myorigin
受信アドレスに基づいて異なる必要がありますが、その方法が見つかりません。これまで多くの解決策を試しましたが、失敗しました。
失敗しました...
2 つの SMTP マスター サービス(127.0.0.1:smtp
と)を作成しようとしましたが、myorigin オプションはプロセス trivial-rewrites に関連しているため、無視されます。myorigin = $myhostname
192.168.1.2:smtp
myorigin = $mydomain
canonical
/のマッピングはvirtual
、単純な書き換えが実行された後に行われるため、使用できないようです。
のマッピングは、aliases
メッセージが に送信されるよう決定された後に使用されるため使用できないようです$mydestination
が、このメッセージは他の場所に送信されます。
答え1
感謝不安フィードバック解決策を見つけました。
解決案
によるとPostfix 公式ドキュメント書き換えに関しては、マスタープロセスツリーは次のようになります。
smtp --+--> cleanup --> rewrite --> [queue]
pickup --/
そこで、次のように、localhost 専用のパイプラインを作成しました。
192.168.1.2:smtp --+--> cleanup --> rewrite ------------+--> [queue]
127.0.0.1:smtp --+--> cleanup_local --> rewrite_local --/
pickup -----------/
構成
これはmain.cf
外部 IP 構成を表す構成です。
# configure the global desiderata
# Basic conf (for display purpose, use your own configuration)
# myhostname = hostname.example.test
# mydomain = example.test
# mydestination =
# mynetworks = 127.0.0.0/8,1.2.3.4/32
# Rewrite options
myorigin = $mydomain
append_at_myorigin = yes
local_header_rewrite_clients = permit_mynetworks
sender_canonical_classes = envelope_sender, header_sender
sender_canonical_maps = hash:/etc/postfix/sender_canonical
recipient_canonical_classes = envelope_recipient, header_recipient
recipient_canonical_maps = hash:/etc/postfix/recipient_canonical
# restrictions (redacted for readability)
smtpd_sender_restrictions = permit_mynetworks, reject_non_fqdn_sender, permit
カスタマイズされたパイプラインを使用した構成は次のとおりですmaster.cf
。
# add this for local smtp service
127.0.0.1:smtp inet n - n - - smtpd
-o myorigin=$myhostname
-o cleanup_service_name=cleanup_local
-o inet_interfaces=loopback-only
-o local_header_rewrite_clients=permit_inet_interfaces
# edit pickup sevice with this two options
pickup unix n - n 60 1 pickup
-o myorigin=$myhostname
-o cleanup_service_name=cleanup_local
# add this for local email cleanup
cleanup_local unix n - n - 0 cleanup
-o myorigin=$myhostname
-o rewrite_service_name=rewrite_local
# add this for local email basic rewrite
rewrite_local unix - - n - - trivial-rewrite
-o myorigin=$myhostname
-o local_header_rewrite_clients=permit_inet_interfaces
# Then for each public IP assigned to the machine, add smtp service like this
192.168.3.85:smtp inet n - n - - smtpd
# and remove default service smtp inet [..cut..] smtpd