• Community Support
  • USEnglish
  • "Restrict Mailcow to Only Send/Receive Emails with a Specific Domain"

I have a domain abc.in, which is hosted on Mailcow, and I want to restrict its email communication only to abc.com. This means:

  • abc.in should only be able to send and receive emails from abc.com.
  • Emails to and from any other domains (Gmail, Yahoo, etc.) should be completely blocked.

What is the best way to achieve this in Mailcow?

  • EETNyx

      Moolevel 73

    Hello, I assume abc.com is trusted server, so if you need pure p2p system Mailcow looks like overkill, while using all fancy antispam things and so,..

    Anyway in theory for outgoing mails i would modified transport_map something like

    * discard:
    abc.com smtp:[abc.com]

    And for outgoing i would used smtpd_client_restrictions like

    smtpd_client_restrictions = permit_mynetworks, check_client_access hash:/etc/postfix/allowed_clients, reject

    and allowed_clients

    abc.com OK

    If you are lucky, you could be able to setup this over MC UI in System -> Configuration find Routing, Global filter maps and/or Forwarding Hosts

      Have something to say?

      Join the community by quickly registering to participate in this discussion. We'd like to see you joining our great moo-community!

      ETNyx Could you please help me with how to do this using the Mailcow UI?

      • EETNyx

          Moolevel 73

        Sorry, nope, for example I do not fully understand “Global filter maps” and how they are wired into inner function of MC. I would suggest to use servercow.de Icon official support

        since you want something that is not in regular scope, by my understanding.

          ETNyx Thank you for your help! I asked because doing it this way wasn’t working.

          • Discarded:
            abc.com smtp:[abc.com]

          For outgoing, I used smtpd_client_restrictions like this:

          smtpd_client_restrictions = permit_mynetworks, check_client_access hash:/etc/postfix/allowed_clients, reject

          And in allowed_clients:

          abc.com OK
          • EETNyx

              Moolevel 73

            Postfix can be hard to configure, that is why I suggest to use professional help. I would guess that you made this config in extra.conf right? Are you sure it’s not overridden? For example on per server/service configuration, if I remember it right MC does it on multiple occasion,..

            is there any other way to achieve this?

            2 months later

            If you want a Mailcow-hosted domain (e.g., abc.in) to only send and receive emails to/from one specific domain (e.g., abc.com) and block all other domains (Gmail, Yahoo, etc.), here’s how to do it:

            ✅ Steps to configure:
            Edit /opt/mailcow-dockerized/data/conf/postfix/allow_mailcow_local.regexp
            Add this single-line regex to allow only the desired domains:

            /^(.*@abc.com|.*@abc.in)$/ OK

            🔸 Important: Mailcow reads this file as a single regex line. Writing multiple lines like:

            abc.com OK  
            abc.in OK

            won’t work.

            Edit /opt/mailcow-dockerized/data/conf/postfix/header_checks.regexp
            Add this to block incoming mail from other domains like Gmail or Yahoo:

            /^From:.*@(gmail\.com|yahoo\.com)/ REJECT "Emails from Gmail and Yahoo are not allowed."

            `Edit main.cf and update the following sections:

            smtpd_sender_restrictions =
            ** #COMMENT EVERYTHING ELSE HERE**
            check_sender_access regexp:/opt/postfix/conf/allow_mailcow_local.regexp,
            reject
             
            smtpd_recipient_restrictions =
            ** #COMMENT EVERYTHING ELSE HERE**
            check_recipient_access regexp:/opt/postfix/conf/allow_mailcow_local.regexp,
            reject
             
            header_checks = regexp:/opt/postfix/conf/header_checks.regexp

            Restart Mailcow / Postfix to apply the changes.

            No one is typing