如何配置 postfix 只发送到白名单地址?

puf*_*uff 8 postfix whitelist

我想将 postfix 配置为仅将邮件发送到白名单中的地址。我曾尝试使用smtpd_recipient_restrictionsmain.cf像这样:

smtpd_recipient_restrictions =
    reject_unauth_destination
    check_recipient_access hash:/path/to/whitelist
Run Code Online (Sandbox Code Playgroud)

白名单文件格式为

address@example.com    OK
another@example.com    OK
Run Code Online (Sandbox Code Playgroud)

然后用postmap命令翻译成散列。

尽管如此,中继仍将邮件发送到非白名单地址。我错过了什么?

编辑:我通过sendmail命令发送这封邮件,这显然绕过了 smptd 限制。有没有办法处理这个问题?

编辑 2/故事的其余部分:我花了很多时间尝试通过 SMTP 发送 sendmail 只是为了发现我使用的命令不是 sendmail,而是 postfix 的 sendmail 兼容接口,它模仿了功能但不能告诉据我所知,使用 SMTP。

不过 84104 的解决方案运行良好。

841*_*104 7

您告诉 postfix 拒绝某些类型的邮件并接受其他一些邮件。有可能一些消息没有被过滤器捕获,在这种情况下它们是被允许的。我想你想告诉它只接受(检查)列表并拒绝所有其他的。

smtpd_recipient_restrictions =
    check_recipient_access hash:/path/to/whitelist
    reject
Run Code Online (Sandbox Code Playgroud)

响应编辑:
sendmail(1)使用postdrop(1)notsmtpd(8) 实现类似您正在寻找的东西的一种方法是操纵transport(5)的行为。

main.cf
    transport_maps = hash:/etc/postfix/transport

transport
    address1@domain.tld :
    address2@domain.tld :
    senderaddress@yourdomain.tld :
    * error: Recipient not whitelisted.
Run Code Online (Sandbox Code Playgroud)

注意:如果您不在传输映射中包含发件人的地址,它将无法接收退回邮件。