開発環境からは決められた宛先にしかメールを送れないようにしよう!ってことになった.
googleさんに聞いてみたらいくつかやり方があるみたいだった.
不許可な宛先の場合はlocalに転送して捨てる,みたいな transport なやり方が最初に見つかったんだけど,今回はホワイトリストを作って restrictions でやってみることにした.
なおホワイトリストは正則表現で定義することが要件だったのでそれもあわせてやる.
まずホワイトリスト用に regexp に対応していることを確認
[root@hostname ~]# postconf -m | grep regexp
regexp
次にホワイトリストを作成
[root@hostname ~]# vi /etc/postfix/recipient_whitelist
/@hoge.jp$/ OK
/@hoge.com$/ OK
/^hogehoge@gmail.com$/ OK
/^hogehoge00[1-3].*@gmail.com$/ OK
main.cfで制限アクションを定義
送信者によらずに制限するよう sender_restrictions に追加する
[root@hostname ~]# vi /etc/postfix/main.cf
smtpd_sender_restrictions = check_recipient_access regexp:/etc/postfix/recipient_whitelist,reject
っていうか smtpd_recipient_restrictions がうまくいかなかった...orz
smtpd_sender_restrictions はデフォルトが empty だから足すだけでいいみたいなんだけど
smtpd_recipient_restrictions はデフォルトが permit_mynetworks, reject_unauth_destination となっていて,このへんの順番とかが問題だったのかなぁ?
postfixをreload
[root@hostname ~]# /etc/init.d/postfix reload
これでOK.