0

Is it possible to relay incoming emails dynamically with postfix's relayhost?

relayhost = proxy:mysql:/etc/postfix/email2server.cf

and I used mysql database to query each email with relay host. But did not work. if I defined relayhost = myhost2.tld statically it works.

Am I doing this completely wrong? What is the correct way to achieve this?

Thanks for any answers in advance.

1
  • Please enable statements logging on you db and check what queries are there?
    – neutrinus
    Oct 25 '14 at 18:41
3

You can not use a SQL lookup as relayhost parameter. See the postconf manpage man 5 postconf:

...
relayhost (default: empty)
       The next-hop destination of non-local mail
...

To relay depeding on the recipient email address you have to define the transport_maps parameter in your postfix configuration. In your case this would look like this:

transport_maps = proxy:mysql:/etc/postfix/email2server.cf

transport_maps overwrites the default relayhost setting. Look in man 5 transport to see what postfix expects as SQL query result.

3
  • For some reason my relay server just ignores transport maps. relayhost = xxxx is working fine. But with a transport map nothing! not even error or mail queue.
    – M_R_K
    Oct 26 '14 at 14:46
  • It may be that your destination domain myhost2.tld is not allowed to relay mails. You could try to add the setting relay_domains = proxy:mysql:/etc/postfix/email2server.cf. But without your postfix configuration (postconf -n) and the mysql configuration (cat /etc/postfix/email2server.cf) it's hard to tell what's going wrong.
    – sebokopter
    Oct 26 '14 at 18:50
  • Incoming mails are working fine now. Could you please answer my other question. serverfault.com/questions/640306/… - Thanks
    – M_R_K
    Oct 28 '14 at 23:58

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.