I have a following setup:

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

When someone from the outside attempts to send mail to address ending with @example.com, 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 example.com domain (along with google mail servers).

However, here's the problem. When php application (hosted at linux box) tries to send mail to someuser@example.com (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 @example.com domain to google mail servers (so, to servers specified in MX records), IF and only if a mailbox is not found locally.


Do you need the postfix server to be responsible for example.com? (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 main.cf. 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.

  • I don't need postfix to ever be responsible for example.com. Also, there's no $mydomain variable defined in main.cf. $myorigin is set to example.com. How do I tell it to stop being responsible for example.com? 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 @example.com for root, abuse and postmaster. Usually the default for mydestination is "mydestination = $myhostname localhost.$mydomain localhost" Postfix shouldn't accept all mail for example.com unless $mydomain or example.com is in mydestination. Look carefully, and maybe put the default main.cf 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 main.cf ?

Here is part of main.cf

myhostname = example.com
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = localhost
relayhost = googlemail.host

Mails send to whatever@example.com will be relayed to googlemail.host

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

root: whatever@googlemail.host
  • After searching around for a long, this is the answer that finally worked for me. Per Google (support.google.com/a/answer/2956491?hl=en), the relay host setting should be relayhost = smtp-relay.gmail.com:25 – CtrlDot Aug 28 '14 at 8:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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