大网数据广告活动
服务器运维问答

how do I filter and reject mails in postfix based on the 'to' address

· 52CE 我爱测

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 hav…

问题原文

原帖链接 · 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

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-01-13)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。