postfixでの転送設定

Postfixで特定のサブドメイン宛のメールのみを別のサーバへSMTPで転送する際の設定。

/etc/postfix/main.cf に transport_maps を追加

転送先の情報を含むファイル(後述)のありかをtransport_mapsへ記述する。

transport_maps = hash:/etc/postfix/transport

/etc/postfix/transport の作成

xxx@sub.example.com宛のメールを 172.16.0.1 へ転送する場合は以下の様に記述する。

sub.example.com    smtp:172.16.0.1

smtpの標準じゃないポート(tcp/25)以外を使って通信する場合はポート番号も指定できる。

sub.example.com    smtp:172.16.0.1:1025 

portmapコマンドでhashdbを作成する

portmap /etc/postfix/transport

postfixを再起動

# systemctl restart postfix