# Filter known-bad sender domains from your mail-receiver

**URL:** https://meta.discourse.org/t/filter-known-bad-sender-domains-from-your-mail-receiver/118760
**Category:** Sysadmins
**Tags:** how-to
**Created:** [May 27, 2019, 4:52am UTC](https://meta.discourse.org/t/filter-known-bad-sender-domains-from-your-mail-receiver/118760 "2019-05-27T04:52:40Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![mpalmer](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mpalmer/32/45740_2.png) [@mpalmer](https://meta.discourse.org/u/mpalmer)
#### Post date: [May 27, 2019, 4:52am UTC](https://meta.discourse.org/t/filter-known-bad-sender-domains-from-your-mail-receiver/118760/1 "2019-05-27T04:52:40Z")

</div>

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

1. 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).

2. Create an empty file **on the host** , in `/var/discourse/shared/mail-receiver/etc`, named `sender_access`, by running the following command as `root`:

3. Using the [custom Postfix configuration guide](https://meta.discourse.org/t/customising-direct-delivery-postfix-configuration/118759), set the following environment variable:

Your Postfix system is now ready to accept domains to block.

# Blocking and unblocking domains

The list of domains you want to block is maintained in the file `/var/discourse/shared/mail-receiver/etc/sender_access` on the host. The format is straightforward: just a list of domains, one per line, with the word `REJECT` after it. Here is an example:

```plaintext
example.com REJECT
example.org REJECT
# etc

```

There are other possibilities you can use instead of `REJECT`, but we won’t cover them in this guide; see [the fine manual](http://www.postfix.org/access.5.html) if you want to get super-fancy.

Thus, to add or remove a domain from the list of blocked domains, simply add or remove the relevant line from the file, by editing it **as `root`**.

There is one final step that needs to be taken after editing this file: reloading Postfix. It doesn’t automatically notice that a change has happened, and needs to be told. The quickest and least disruptive way to do this is to send a special signal to Postfix, using this command:

```plaintext
docker kill -s HUP mail-receiver

```

If you then examine the logs for the `mail-receiver` container, you should see Postfix mentioning a config reload.

That’s it. Enjoy a less-abused mail system.

---

<div class="post-metadata">

### Author: ![tobiaseigen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tobiaseigen/32/539204_2.png) [@tobiaseigen](https://meta.discourse.org/u/tobiaseigen)
#### Post date: [May 27, 2019, 5:24pm UTC](https://meta.discourse.org/t/filter-known-bad-sender-domains-from-your-mail-receiver/118760/2 "2019-05-27T17:24:28Z")

</div>

Thanks, Matt! Much appreciated. I owe you at least a 🍺 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.

---

<div class="post-metadata">

### Author: ![mpalmer](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mpalmer/32/45740_2.png) [@mpalmer](https://meta.discourse.org/u/mpalmer)
#### Post date: [May 28, 2019, 4:45am UTC](https://meta.discourse.org/t/filter-known-bad-sender-domains-from-your-mail-receiver/118760/3 "2019-05-28T04:45:09Z")

</div>

> [@tobiaseigen](#):
>
> In setup above, you use the `/var/docker..` path when I think you mean `/var/discourse..`

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.

---

<div class="post-metadata">

### Author: ![tobiaseigen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tobiaseigen/32/539204_2.png) [@tobiaseigen](https://meta.discourse.org/u/tobiaseigen)
#### Post date: [May 28, 2019, 2:02pm UTC](https://meta.discourse.org/t/filter-known-bad-sender-domains-from-your-mail-receiver/118760/4 "2019-05-28T14:02:58Z")

</div>

> [@mpalmer](#):
>
> hysterical raisins

hysterical. 😆

---

<div class="post-metadata">

### Author: ![satonotdead](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/satonotdead/32/447830_2.png) [@satonotdead](https://meta.discourse.org/u/satonotdead)
#### Post date: [April 9, 2020, 9:03pm UTC](https://meta.discourse.org/t/filter-known-bad-sender-domains-from-your-mail-receiver/118760/5 "2020-04-09T21:03:06Z")

</div>

Can we implement a more robust system to block incoming spam or maybe using more possibilities (detailed in Postfix manual) could be enought?

Thanks for that guide!

---

<div class="post-metadata">

### Author: ![mpalmer](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mpalmer/32/45740_2.png) [@mpalmer](https://meta.discourse.org/u/mpalmer)
#### Post date: [April 12, 2020, 9:39pm UTC](https://meta.discourse.org/t/filter-known-bad-sender-domains-from-your-mail-receiver/118760/6 "2020-04-12T21:39:46Z")

</div>

Yes, you can certainly implement a more robust system to block incoming spam.

---

<div class="post-metadata">

### Author: ![satonotdead](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/satonotdead/32/447830_2.png) [@satonotdead](https://meta.discourse.org/u/satonotdead)
#### Post date: [April 12, 2020, 11:05pm UTC](https://meta.discourse.org/t/filter-known-bad-sender-domains-from-your-mail-receiver/118760/7 "2020-04-12T23:05:32Z")

</div>

Can you share some link or idea to start with?

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [April 13, 2020, 3:09am UTC](https://meta.discourse.org/t/filter-known-bad-sender-domains-from-your-mail-receiver/118760/8 "2020-04-13T03:09:37Z")

</div>

Whole literal books could be written about spam and email servers. Is it really fair to ask us for that level of instruction? Perhaps give it a google or two?

---

<div class="post-metadata">

### Author: ![satonotdead](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/satonotdead/32/447830_2.png) [@satonotdead](https://meta.discourse.org/u/satonotdead)
#### Post date: [April 13, 2020, 3:39am UTC](https://meta.discourse.org/t/filter-known-bad-sender-domains-from-your-mail-receiver/118760/9 "2020-04-13T03:39:46Z")

</div>

Sorry, it’s not the idea. I just ask for personal recommendations from Discourse experienced users.

I’ll look into it by my own, of course.
