从你的邮件接收器中过滤已知的不良发件人域名

如果您 自行运行传入邮件,并且发现收到的垃圾邮件超出了您的承受范围,本指南将为您提供帮助!它将向您展示如何配置 mail-receiver 容器,以阻止来自您创建列表中的任意域名的电子邮件,并说明如何随时间添加和移除域名。

设置

  1. 使用 自定义 Postfix 配置指南,配置您的 mail-receiver 容器,使其拥有一个 /etc/postfix/shared 卷(请参阅底部的“附录”部分)。

  2. 主机上创建一个空文件,路径为 /var/discourse/shared/mail-receiver/etc,文件名为 sender_access,以 root 用户身份运行以下命令:

    touch /var/discourse/shared/mail-receiver/etc/sender_access
    
  3. 使用 自定义 Postfix 配置指南,设置以下环境变量:

     env:
       # <existing config>
       POSTCONF_smtpd_sender_restrictions: 'texthash:/etc/postfix/shared/sender_access'
    

现在,您的 Postfix 系统已准备好接受要阻止的域名。

阻止和解除阻止域名

您希望阻止的域名列表保存在主机上的文件 /var/discourse/shared/mail-receiver/etc/sender_access 中。格式非常简单:只需列出域名,每行一个,并在其后加上单词 REJECT。示例如下:

example.com    REJECT
example.org    REJECT
# 等等

除了 REJECT 之外,您还有其他选择可以使用,但本指南不会涵盖这些内容;如果您想深入了解,请参阅 官方手册

因此,要从阻止域名列表中添加或移除域名,只需以 root 身份编辑该文件,添加或移除相应的行即可。

编辑此文件后,还需要完成最后一步:重新加载 Postfix。它不会自动检测到更改,需要您手动通知。最快捷且干扰最小的方法是使用以下命令向 Postfix 发送特殊信号:

docker kill -s HUP mail-receiver

随后,如果您检查 mail-receiver 容器的日志,应该会看到 Postfix 提到配置已重新加载。

就是这样。享受一个更少受到骚扰的邮件系统吧。

17 个赞

Thanks, Matt! Much appreciated. I owe you at least a :beer: for this super helpful howto. I have now implemented the above and added the offending domains to it - I’ve let it go for an hour and so far it’s been quiet.

One clarification: In setup above, you use the /var/docker.. path when I think you mean /var/discourse.. - though I suspect different instances may use different paths depending on when they were set up. These days I suspect most people use /var/discourse.. which is also reflected in the other howto you link to for setting up direct delivery.

6 个赞

You are correct. For hysterical raisins we use /var/docker internally, so that’s the path that comes to mind. I’ve updated the howto.

5 个赞

hysterical. :laughing:

3 个赞

我们能否实施一个更完善的系统来拦截传入的垃圾邮件,或者利用更多可能性(在 Postfix 手册中有详细说明)就足够了?

感谢这份指南!

1 个赞

是的,您完全可以通过实施更强大的系统来拦截垃圾邮件。

2 个赞

你能分享一些链接或想法作为入门吗?

关于垃圾邮件和电子邮件服务器,足以写成整本整本的专著。真的要求我们提供如此详尽的指导公平吗?或许您可以先自行搜索一下?

抱歉,这不是我的本意。我只是想向有 Discourse 使用经验的用户寻求个人建议。

当然,我也会自行研究。