Hey everyone,
I need your help with configuring Mailcow (latest version, fresh Install, with Backups before every try in Case I break something). I want to set up Postfix so that incoming emails to existing mailboxes are delivered normally and locally. However, if an email is sent to a mailbox that is not present in the virtual mailbox table (i.e., does not exist), I want this email to be forwarded to a relay host.
The key point is that both the local and the forwarded mailboxes use the same domain. So it’s really about distinguishing based on the existence of individual mailboxes.
Example:
My domain is example.com.
Emails to existing mailboxes like user1@example.com or user2@example.com should be delivered locally.
Emails to non-existent mailboxes like unknown@example.com or test@example.com should be forwarded to a relay host at [relay.example.net]:25.
Outgoing emails, for example those sent via the SOGo web interface or by users via SMTP, should not go through the relay host but should be sent directly through the internet.
What I’ve tried so far:
Using the tools available through the Mailcow web interface, I only managed to either relay all emails or none of the incoming emails (resulting in the sender receiving an error). I had partial success with manual configuration in the Postfix configuration and the MySQL database, but in the end that didn’t work either. Moreover, I’m unsure if my manual changes would persist through updates.
Given a few more hours, I might be able to figure it out, but perhaps there is a simple “official” solution for this.
My question:
How can I configure Mailcow and Postfix to achieve this behavior? Is there a way to set up Postfix so that it checks for the existence of a mailbox and, if it doesn’t exist, forwards the email to the relay host?
I’ve attempted to use virtual_alias_maps and transport_maps, but haven’t had success so far. Maybe someone here has implemented a similar configuration or can provide steps on how to set up this configuration.
I noticed that the English-speaking community is larger here, so I wrote this post in English. However, please feel free to reply in German if that’s easier for you.
I hope this is the correct forum section for this question.
Thank you in advance for your help!