问题原文
原帖链接 · pi. · CC BY-SA 3.0
My CentOS server is configured for outgoing mail only. I need a filter to reject mails targeted at selected destinations. For example, if I test with
> mail -s "test" [email omitted]
I want this to be rejected and not sent. I have explored the
smtpd_recipient_restrictions
flag [and others] but I have not been able to get that working. The logs still show that the mail was sent and removed from the queue.
Within the main.cf file, and under the smtpd_recipient_restrictions, I have:
> check_sender_access hash:/etc/postfix/maps/access_sender
where I have, for example
@trash.com REJECT
I wish to add that this server relays mails to another but I am hoping that I can filter out unwanted mails before relaying to host. Please help. Thanks
已采纳解答
原帖链接 · Craig Watson · CC BY-SA 3.0
The check_sender_access option only applies to the "From" address. To filter based on the "To" address, you can do this in one of two ways.
If you want to filter on just the "To" address, just change the check_sender_access to check_recipient_access and keep your current hash file.
A more extensible way to filter is by headers. Add the following into your main.cf file:
header_checks = regexp:/etc/postfix/header_checks
Then create the following file at /etc/postfix/header_checks:
/^To:.*[email omitted].*$/ DISCARD blocked
/^To:.*[email omitted].*$/ DISCARD blocked
/^To:.*[email omitted].*$/ DISCARD blocked
/^To:.*[email omitted].*$/ DISCARD blocked
And restart Postfix.
Note - DISCARD will still appear to send the message, but the message will be silently discarded. If you want to force the message to be bounced, use REJECT.
Reference documentation:
http://www.postfix.org/postconf.5.html#smtpd_recipient_restrictions http://www.postfix.org/header_checks.5.html
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
