2023年7月21日 星期五

利用postfwd限制postfix的user每天的寄件數量

1.安裝postfwd

sudo apt-get update

sudo apt-get install postfwd

2.配置 postfwd規則
設定檔是/etc/postfix/postfwd.cf,若不存在,直接新增一個,並編寫內容如下:
# 限制每個帳號每日寄件總數為 500 封,並記錄日誌,sender 是內定參數
id=sender_rate
        action=rate(sender/500/86400/REJECT 550 User $$sender reached daily sending limit)
3.修改postfix的main.cf檔案內容,找到 "smtpd_recipient_restrictions =",並將 "check_policy_service inet:127.0.0.1:10040"加在這個項目的最上方!
smtpd_recipient_restrictions =
#postfwd
        check_policy_service inet:127.0.0.1:10040
        ..............................
        ..............................
4.將postfwd設為開機啟動,並啟動!
sudo systemctl enable postfwd
sudo systemctl start postfwd

5.重新啟動postfix
sudo systemctl restart postfix