![Exim 條件邏輯](https://rvso.com/image/747348/Exim%20%E6%A2%9D%E4%BB%B6%E9%82%8F%E8%BC%AF.png)
我試圖讓 exim 根據網域清單檢查傳出和傳入郵件的網域。如果發出郵件的寄件者地址和收到郵件的收件者/副本/密件副本地址不在本機網域清單中,我想拒絕/丟棄該郵件。以下是我提出的內容,放在「acl_not_smpt」部分:
discard
condition = ${if and {{! match_domain{${domain:${address:$h_from:}}}{+local_domains}}\
{if or {\
{! match_domain{${domain:${address:$h_to:}}}{+local_domains}}}\
{! match_domain{${domain:${address:$h_cc:}}}{+local_domains}}}\
{! match_domain{${domain:${address:$h_bcc:}}}{+local_domains}}}\
}\
}\
}\
message = Mail discarded for spoofing
但我在我的 exim 日誌中收到以下錯誤:
“and{...}”條件內的未知條件“if”
exim 語法非常新,希望能得到一些幫助。
答案1
第二個if
是不正確的,事實上你不需要它:and
條件可以使用任何布林函數(參見擴張條件),而$if
傳回一個字串(參見擴充項目和擴充運算符)。還有一些額外的}
。工作狀態變成:
condition = ${if and {\
{!match_domain{${domain:${address:$h_from:}}}{+local_domains}}\
{ or {\
{! match_domain{${domain:${address:$h_to:}}}{+local_domains}}\
{! match_domain{${domain:${address:$h_cc:}}}{+local_domains}}\
{! match_domain{${domain:${address:$h_bcc:}}}{+local_domains}}\
}}\
}}
這種情況有一些錯誤:它不檢查多個收件人和From:
地址。
另請注意,acl_not_smtp僅當(本機)使用者使用以下命令呼叫 exim4 時才執行 ACL-bm 或 -bS 選項。這表示您的 ACL 將阻止本機使用者發送外發郵件。
如果這就是您想要做的,那麼您的表達式可以簡化:
From:
配置 Exim 可以更有效地完成標頭檢查可信任用戶。您可以使用變量,該變量將所有這些包含在一個單獨的字串中,而不是單獨檢查
To:
,Cc:
和。Bcc:
$recipients
,
所有這些相當於兩個 ACL 節:
accept
condition = ${if forall {<,${recipients}}\
{match_domain{${domain:${item}}}{+local_domains}}\
}
deny
一般來說,您可以SMTP
透過建立(或儲存)電子郵件(例如email.eml
)並運行來偵錯字串擴充和非 ACL:
exim4 -d-all+acl+expand -bm -t < email.eml
作為根(警告:這將嘗試真正的電子郵件傳遞),同時檢查擴充功能運行:
exim4 -bem email.eml