Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a following setup:

  • linux box with postfix configured to be responsible for domain
  • domain's MX servers are configured so that mail sent to is sent to google mail servers
  • several user accounts on linux machine exist (same machine also hosts site)

When someone from the outside attempts to send mail to address ending with, it gets routed to google mail (and there handled appropriately).

When linux machine tries to send mail to outside world, mail is delivered correctly, as reverse dns and spf records are configured correctly, so linux machine is valid mail sender for domain (along with google mail servers).

However, here's the problem. When php application (hosted at linux box) tries to send mail to (and someuser doesn't exist on linux box), it fails, since it doesn't even consult google mail servers, but postfix smtp locally concludes that "someuser" is unknown.

So, the question is: how do I tell postfix to relay mails sent to domain to google mail servers (so, to servers specified in MX records), IF and only if a mailbox is not found locally.

share|improve this question
Did you set "relayhost" in ? – derchris Mar 20 '11 at 20:24
@derchris: relayhost is empty. – mr.b Mar 20 '11 at 23:02
See also "Postifx disable local delivery". – JdeBP Jun 2 '11 at 16:09
up vote 6 down vote accepted

Do you need the postfix server to be responsible for (Do you ever want mail to be delivered there instead of to google?) If you always want mail for local example users to go to their google, remove $mydomain from the mydestination parameter in This will not alter where the mails appear to be coming from for outside users. (That is controlled by "myorigin")

Since postfix either thinks it is responsible for the domain or not, there is no easy way to split the domain up so some mail gets delivered locally and some gets delivered to google. You can do some tricks by putting in forwarding rules or with transport mapping, but then you'd need to specify google or local for each user. I kind of doubt you really want to do that.

share|improve this answer
I don't need postfix to ever be responsible for Also, there's no $mydomain variable defined in $myorigin is set to How do I tell it to stop being responsible for Also, what will happen when mail is sent to root locally, for example? Will postfix consider /etc/aliases (I have enabled them)? – mr.b Mar 20 '11 at 23:18
Postfix should always handle /etc/aliases, so feel free to put a different email address for root, abuse and postmaster. Usually the default for mydestination is "mydestination = $myhostname localhost.$mydomain localhost" Postfix shouldn't accept all mail for unless $mydomain or is in mydestination. Look carefully, and maybe put the default back in place and work off that. There are a few other ways to get this wrong, using transports and the like, but you don't need them. – mfarver Mar 20 '11 at 23:24

Did you set "relayhost" in ?

Here is part of

myhostname =
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = localhost
relayhost =

Mails send to will be relayed to

In /etc/aliases you can provide an alias for the root user for local delivery, like

share|improve this answer
After searching around for a long, this is the answer that finally worked for me. Per Google (, the relay host setting should be relayhost = – Nick Hebb Aug 28 '14 at 8:00

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.