Bypassing relayhost in Postfix?

cihan

Member
Mar 8, 2022
2
2
8
37
Hello,

I've spent my all day trying to achieve this, with no success.

Here is the deal:
We use PMG as outgoing mail gateway. Permitted networks can relay mail to PMG, PMG filters these mails and then relays the mail to a smarthost.
There are thousands of sender domains, which is why we use permitted networks, because adding domains to PMG is not practical nor possible.

we use relayhost= option in postfix main.cf to relay emails to the smarthost.

Now the problem is that when we add "notify" to any spam action, also notification emails are being relayed to smarthost. Which is not what we want. All emails generated my PMG should be sent from localhost instead.

We tried "sender_dependent_relayhost_maps" option in order to achieve this but this option doesn't have wildcard option therefore useless. Because;
If we don't use relayhost= and use sender_dependent_relayhost_maps, we specify different smarthosts for different domains. Which works fine. But sender_dependent_relayhost_maps doesn't accept wildcard. So if domain is not in sender_dependent_relayhost_maps file, it is being sent locally.

if relayhost=xxxxx specified, we can override relayhost for certain domains using sender_dependent_relayhost_maps, but there is no option for "do not relay for this domain". It only accepts smarthosts. I can specify different smarthosts but I cannot make it "not relay".

Any help will be appriciated regarding this issue.

Thanks in advance.
 
After hours of trial and research, I was able to do that.

So we'll not use relayhost= and we'll use this instead:
default_transport = relay:[smarthosthere]:25
instead of sender_dependent_relayhost_maps, we'll use this:
sender_dependent_default_transport_maps = hash:/etc/postfix/transport

/etc/postfix/transport:
@domainnottorelay smtp:

Hopefully this saves someone from hours of research.