Forward email to other servers if the recipient doesn’t exist in alias map

emailpostfix

This is the first time I am starting to write a more complex postfix as I hate setting up mail settings without knowing what to do. But right now I am required to do.

Here the setting:

For internal reasons I am required to have my postfix relay set up like this:

If recipient of an email is doesn't exist in alias map but the recipient domain does, postfix will send it to real mail server.

Okay, this reads strange, but I am giving you an example.

MX record of example.com is set to ProxyHost but the real mailserver with all accounts is reachable under external.example.com

In mysql I have setup redirect@example.com should be forwarded to my@example.net. This is working right now.

But if I am sending a mail to whatever@example.com where whatever is NOT in the local mysql forwarding table but as you can see example.com is, I would love to forward the mail to the real mail server. This real server information was located in the domains table in the realmx column.

This does not look very hard on me, but I am not able to handle it. Right now all mails to whatever@example.com are just getting rejected.

Best Answer

That's a very standard and typical setup. Postfix runs on a server which is external facing and receives mail and passes it on to the server which has the mailbox:

world -> smtp.example.com -> imap.example.com

On your smtp server (which you call ProxyHost but I won't use this term as it's not really a proxy in the general usage of the term), you will use configurations as follow (you'll have to adjust to your exact scenario, these are general guidelines):

mydestination = localhost
transport_maps = hash:/etc/postfix/transport
relay_domains = example.com
relay_recipient_maps = hash:/etc/postfix/relay_recipients

/etc/postfix/relay_recipients will contain the list of valid recipients.

/etc/postfix/transport will list the destination for the final destination of the mail.

Full documentation and complete explanation of each configurations above can be found in the great Postfix manual. Start with the relay_domains documentation.