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.