iT邦幫忙

0

postfix寄信權限設定問題

請問postfix是否能設定成, 內部特定email只能寄到外部特定email, 其他都無法寄出
ex:
john@abc.com 只能寄到 mary@gmail.com & alicia@hotmail.com
若寄其他email則無法寄出

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

1
過時軟碟片
iT邦新手 5 級 ‧ 2021-04-06 12:23:22
最佳解答

關於你的問題其實可以參考Postfix的文件Postfix Per-Client/User/etc. Access

可以的話我稍晚可能可以詳列步驟。

[EDIT]
那麼我來寫步驟吧。

我針對你的問題提出對應的設定參考,作法的概念是先鎖定欲限制的收件者再回頭檢查是否為指定的送件者。這兩部份都必須要在lookup table中查找所以對於第二部份的 查找送件者 就必須要用上面文件提到的Postfix restriction classes的作法。

所以首先先把查找送件者的lookup table設定放在main.cf的設定檔裏面,如下︰

smtpd_restriction_classes = deny_john_abc_com
deny_john_abc_com = check_sender_access regexp:/etc/postfix/check_sender_access

第1行宣告一個smtpd_restriction_classes叫做deny_john_abc_com,第2行定義deny_john_abc_com是一個check_sender_access的hash table /etc/postfix/check_sender_access,待會我們再來看這個檔案的內容。

現在來處理查找收件者的部份,請在你的main.cf中的smtpd_recipient_restrictions設定插入一個check_recipient_access的設定,請注意把這個設定擺在任何permit_xxx之前,因為原先的permit_xxx應該沒有做過濾就放行了吧,舉例如下︰

smtpd_recipient_restrictions = check_recipient_access regexp:/etc/postfix/smtpd_recipient_restrictions, permit_
mynetworks ..... reject_....

這行設定中我把check_recipient_access放在第1項因為原本第1項就是permit_mynetworks。至於這個smtpd_recipient_restrictions的內容如下︰

!/^(mary@gmail\.com|alicia@hotmail\.com)$/	deny_john_abc_com

這一行是針對「非」收件者mary@gmail.comalicia@hotmail.com(注意開頭的驚嘆號),動作就是那個最先定義的那個smtpd_restriction_classes叫做deny_john_abc_com。

那麼現在來看deny_john_abc_com的hash table "check_sender_access"的內容,不難想像就是要把指定的送件者reject掉。所以check_sender_access的內容如下︰

john@abc.com    REJECT john@abc.com isn't allowed to send mail to specific recipients.

只有一行,就是針對john@abc.com的對應動作是REJECT,而接著的文字是寫一些說明,這說明會回給SMTP client也會紀錄在syslog裏。

最後要做的就是套用設定了,所以先編譯一下hash table然後再restart postfix,

someone@server:/etc/postfix$ sudo postmap hash:check_sender_access
someone@server:/etc/postfix$ sudo systemctl restart postfix

這是2行shell指令,假設是在debian或ubuntu環境。

額外說明的是,你可以定義多個smtpd_restriction_classes來針對不同的限制條件當然在那兩個table中就要做些針對不同條件的增列或甚至追加更多的table,最後記住如果你table是hash的話要先用postmap編譯一下。

bbq925 iT邦新手 5 級 ‧ 2021-04-06 17:27:05 檢舉

已完成設定, 非常感謝!

我要發表回答

立即登入回答