使用 Postfix 阻止外发邮件到特定地址

Mai*_*kel 12 postfix

如何使用 Postfix 阻止发往特定地址的外发邮件?

我已经部分设法使用header_checks. 但是,header_checks 不包括密件抄送。

我还测试了这个解决方案:http : //www.linuxmail.info/postfix-restrict-sender-recipient/ 但它没有用。

Mat*_*enz 12

阻止任何人(本地(邮件/sendmail 命令)系统用户和 SMTP 用户)发送到您不能依赖的电子邮件地址smtpd_recipient_restrictions。您需要将限制置于qmgr灵态中。为此,我发现transport_maps效果很好。

main.cf

transport_maps = pcre:/etc/postfix/transport_maps
Run Code Online (Sandbox Code Playgroud)

transport_maps

/^user(\+[^@]+)?@host\.com/ discard:
/.*/ :
Run Code Online (Sandbox Code Playgroud)

也许有更好的解决方案,但这个解决方案似乎适用于所有交付类型。仅供参考,该正则表达式支持user@host.comuser+anything@host.com假定+分隔符。它可以防止 To、CC 和 BCC。

还要确保您的 postfix 启用了 pcre 支持。在由 postfix-pcre 包提供的基于 Debian(Ubuntu 等)的操作系统上。


小智 7

最简单的方法是执行此操作,无需正则表达式支持:

  1. main.cf如果尚不存在,请将其添加到:

    transport_maps = hash:/etc/postfix/transport
    
    Run Code Online (Sandbox Code Playgroud)
  2. 根据需要向文件“/etc/postfix/transport”添加行

    # silently discard a single address
    address_to_discard@example.com discard
    
    # silently discard an entire domain
    example.net discard
    
    # return an error to the sending MTA
    address_to_error@example.com error:Invalid user
    
    Run Code Online (Sandbox Code Playgroud)
  3. 运行postmap

    postmap /etc/postfix/transport
    
    Run Code Online (Sandbox Code Playgroud)
  4. 重新加载 postfix 服务(或者等待约 1 分钟,Postfix 将自动更新)

    service postfix reload
    
    Run Code Online (Sandbox Code Playgroud)


ada*_*ptr 5

access(5) 中所述,只需将 check_recipient_access 映射添加到您的 smtpd_recipient_restrictions;如果你想阻止这些收件人为自己的用户太多,请务必将其放在permit_mynetworks和/或permit_sasl_authenticated。

smtpd_recipient_restrictions = check_recipient_access hash:/etc/postfix/bad_recipients, permit_mynetworks, reject_unauth_destination, permit
Run Code Online (Sandbox Code Playgroud)

在 /etc/postfix/bad_recipients 中:

bad_user1@example.com REJECT We don't like him
bad_user2@example.org REJECT Delivery to this user is prohibited
Run Code Online (Sandbox Code Playgroud)