Postfix sender_bcc_maps /忽略特定用户

Postfix sender_bcc_maps /忽略特定用户

我已设置 sender_bcc_maps 并与 postfix 配合使用,以便外发邮件可以密件抄送给发件人的地址。我的配置大致如下:

主配置文件

sender_bcc_maps = regexp:/etc/postfix/regexp_sender_bcc

regexp_sender_bcc

/^([^@]+)@[a-zA-Z0-9_]+\.[a-zA-Z0-9_]+$/ [email protected]

这很管用。现在我有了一个电子邮件地址[email protected],我想排除从此配置。

想法1:我首先尝试添加一行来路由到一个不存在的邮箱

/^nobody.*$/ [email protected]

可以预见的是,这会导致尝试密送该地址,但由于该地址不存在而被退回。

想法2:接下来我尝试简单地将目标更改为空字符串:

/^nobody.*$/

这将生成一个警告,并且完全删除外发邮件:

warning: sender_bcc_maps lookup of [email protected] returns an empty string result
warning: sender_bcc_maps should return NO RESULT in case of NOT FOUND
warning: sender_bcc_maps map lookup problem -- message not accepted, try again later

想法3:然后我尝试将这封邮件路由给本地用户:

/^nobody.*$/ nobody@localhost

这在某种程度上起到了作用,但所有这些消息仍然会被传递到本地邮件系统。

我想做其中任何一件事 - 更喜欢前者:

  • 配置 sender_bcc_maps 为完全忽略特定发件人的地址
  • 配置 postfix 以彻底丢弃发邮件给特定用户

答案1

配置 sender_bcc_maps 以完全忽略特定发件人的地址:

(感谢 Viktor Dukhovni 通过以下方式回答了这个问题postfix 用户

后缀正则表达式表能够使用 进行条件否定模式匹配if !/pattern/flags ... endif。在我的例子中,以下内容实现了我想要的结果:

if !/^nobody@/
/^([^@]+)@[a-z-]+\.[a-z]+/ [email protected]
endif

正如指出的那样,正则表达式默认不区分大小写,因此对模式的域匹配部分也有一些小的改进。

配置 postfix 以完全丢弃发往特定用户的邮件:

以下步骤对我有用,可以默默丢弃指定用户的邮件。服务器正在运行 Ubuntu 20.04.3 LTS,但这应该适用于几乎所有 Debian 版本:

/etc/postfix/main.cf

transport_maps = hash:/etc/postfix/transport

/etc/postfix/transport

[email protected] discard:

然后在 shell 中运行:

postmap /etc/postfix/transport
service postfix restart

相关内容