Filter known-bad sender domains from your mail-receiver

If you run your own incoming mail, 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, 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:

    touch /var/discourse/shared/mail-receiver/etc/sender_access
    
  3. Using the custom Postfix configuration guide, set the following environment variable:

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

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:

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 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:

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.

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에 경험이 있는 사용자분들께 개인적인 추천을 요청드린 것입니다.

물론 제 스스로 알아볼 것입니다.