# 如何屏蔽垃圾邮件

**URL:** <https://meta.discourse.org/t/how-to-block-mail-spammers/274081>\
**Category:** Support\
**Created:** [2023年八月6日 03:53 UTC](https://meta.discourse.org/t/how-to-block-mail-spammers/274081 "2023-08-06T03:53:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andro](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/andro/32/173721_2.png) [@Andro](https://meta.discourse.org/u/Andro)\
**Post date:** [2023年八月6日 03:53 UTC](https://meta.discourse.org/t/how-to-block-mail-spammers/274081/1 "2023-08-06T03:53:57Z")

</div>

我的网站收到了发往不存在地址的垃圾邮件，这很烦人。邮件当然会失败，但它会使日志变得混乱。由于我没有源 IP 地址，有什么方法可以按源地址阻止电子邮件吗？我知道它们一直在变化，但我在寻找建议。我的 Discourse 是自托管的。

---

<div class="post-metadata">

**Author:** ![Lilly](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/lilly/32/575047_2.png) [@Lilly](https://meta.discourse.org/u/Lilly)\
**Post date:** [2023年八月6日 04:04 UTC](https://meta.discourse.org/t/how-to-block-mail-spammers/274081/2 "2023-08-06T04:04:53Z")

</div>

这个主题可能对您有帮助，如果您还没有看过的话：

> [@Filter known-bad sender domains from your mail-receiver](https://meta.discourse.org/t/filter-known-bad-sender-domains-from-your-mail-receiver/118760):
>
> If you [run your own incoming mail](https://meta.discourse.org/t/straightforward-direct-delivery-incoming-mail/49487), and you find that you’re getting more abusive mail than you’re willing to tolerate, this guide is for you! It’ll show you how to configure your mail-receiver container to block e-mail from any domain on a list you create, and how you can add and remove domains from that list over time. Setup Using the [custom Postfix configuration guide](https://meta.discourse.org/t/customising-direct-delivery-postfix-configuration/118759), configure your mail-receiver container to have an /etc/postfix/shared volume (see the “Addendum” section at the bottom). …

---

<div class="post-metadata">

**Author:** ![md-misko](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/md-misko/32/126315_2.png) [@md-misko](https://meta.discourse.org/u/md-misko)\
**Post date:** [2023年八月6日 07:20 UTC](https://meta.discourse.org/t/how-to-block-mail-spammers/274081/3 "2023-08-06T07:20:51Z")

</div>

> [@Andro](#):
>
> 由于我没有源 IP 地址

您可以使用此命令从日志中过滤掉大多数垃圾邮件发送者的 IP 地址（这不是严格的 RFC 要求，但几乎所有垃圾邮件中继都没有有效的 PTR）

```plaintext
./launcher logs mail-receiver | grep -v 'unknown' | grep -E 'NOQUEUE'

```

如果您收到来自看似合法服务器的垃圾邮件，仍然很难使用电子邮件域阻止发件人，因为它很容易被伪造，所以您最好的办法是找到发送 SMTP 服务器的 IP 地址并阻止它

```plaintext
./launcher logs mail-receiver | grep -E '[0-9A-F]{10,}:.+(from=\u003c[^\u003e]|client=)'

```

第一对结果将为您提供 SMTP 服务器 IP，第二个结果将为您提供发件人地址。

您可以使用以下链接中描述的说明来配置 mail-receiver：

> [@Mail-receiver loses IP to hostname resolution after recent upgrade and prevents anti-spam measures from working](https://meta.discourse.org/t/mail-receiver-loses-ip-to-hostname-resolution-after-recent-upgrade-and-prevents-anti-spam-measures-from-working/205003?u=md-misko):
>
> It seems that latest [Self-hosted mail-receiver update following Let's Encrypt root certificate change](https://meta.discourse.org/t/self-hosted-mail-receiver-update-following-lets-encrypt-root-certificate-change/204924/1) mail-receiver update doesn’t resolve IPs to hostnames any more. This causes issues with previously working postfix client access restrictions, enabled by adding the following line to mail-receiver.yml: POSTCONF\_smtpd\_client\_restrictions: 'regexp:/etc/postfix/shared/client\_access\_regex' This is a snippet from the mail-receiver log, showing an inbound connection: Oct 01 17:38:11 discourse-mai…

我通过这种方法几乎消除了所有的垃圾邮件。

---

<div class="post-metadata">

**Author:** ![Ed\_S](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ed_s/32/134015_2.png) [@Ed\_S](https://meta.discourse.org/u/Ed_S)\
**Post date:** [2023年八月6日 10:50 UTC](https://meta.discourse.org/t/how-to-block-mail-spammers/274081/4 "2023-08-06T10:50:33Z")

</div>

> [@Andro](#):
>
> it clogs up the logs

这听起来像是一个小小的行政不便——与阻止真人为您的论坛做出实际贡献的不完美封锁的影响相比。就我个人而言，我不会使用任何形式的封锁，因为我永远不想丢失有效输入，即使代价是获得一些无效输入。
