I have a quick question. How do I setup postfix to send an email to another server (Exchange Server) when sending to an email address that has a sub-domain of our main server. For example, say our main server is mail.example.com and we have a Exchange server setup to receive emails from exchange.example.com. We have the MX records setup in our DNS and it receives correctly if we send from a GMail account. However, when we try to send an email from a @example.com account we get the following error:
Host or domain name not found. Name service error for name=exchange.example.com type=A: Host not found
I believe Postfix checks for local mailboxes first and if its setup with the domain it delivers to the local account, but in this case the sub-domain accounts are located in another server. Anyone have any thoughts on what I need to do within Postfix so it doesn't look locally for the exchange.example.com mailboxes?
I found relay_domains directive within Postfix but that doesn't seem to fix it when I add the sub-domain.
Thanks for your help.
It seems that you're trying to set up an SMTP gateway, and do not want to expose your Exchange Server to the "outside" network, right? Because usually I'd just set up the appropiate MX records for the domain.
Postfix, by design, won't accept mails for foreign domains, but postfix wouldn't be postfix if it wouldn't be possible. It just requires you to do a bit more work, for example, telling postfix which email-adresses are valid (it can't determine this by itself for a subdomain, naturally). It's well explained over here: http://www.knowplace.org/pages/howtos/smtp_gateway_for_multiple_domains_with_postfix.php
The error seems to indicate that exchange.example.com does not exist in DNS. In order for postfix to find the exchange server, it has to be able to resolve the exchange.example.com domain name to an ip address, so it knows where to route it.
relay-domains is indeed the correct parameter, but it is not all you need to do.
Run
postconf parent_domain_matches_subdomains
and check if relay_domains is present; if it is, add the line to main.cf and remove relay_domains from the list (or unset the option entirely, but make sure you understand the consequences.)