Sender-transport maps with additional services would do the trick. From the docs, ApisCP already provides a map to use.
To allow authless SMTP from additional IP ranges, override mynetworks. This is covered in the “Customizing” section of the docs.
To declare specific SMTP relays, there are two approaches: either create a new service in master.d/ or set the literal next-hop.
# master.d/google-relay.cf, see docs
google-relay - - n - - smtp
-o relayhost=[smtp.google.com]:587
/etc/postfix/sender_transport
@domain1.tld google-relay:
Run postmap /etc/postfix/sender_transport after
Alternatively:
/etc/postfix/sender_transport
@domain1.tld smtp:[smtp.google.com]:587
Run postmap /etc/postfix/sender_transport after
Then wire up authentication for the relay:
/etc/postfix/smarthost-auth
[smtp.google.com]:587 USERNAME:PASSWORD
Run postmap /etc/postfix/smarthost-auth after
Restart postfix service and those relays will be used if the sending domain matches. Pattern the remaining 2 SMTP relays and sender domains based off the above examples. Using a declared SMTP service deduplicates the SMTP relay and allows customization down the road, like throttling relay rates.
This currently makes sense and seems to be correct. However, outbound email isn’t routed through the Google relay nor MXroute. Seems to be ignored and delivered by postfix directly, or at least that’s what I’m reading in the email headers.
Already ran postmap and upcp -sb mail/configure-postfix. Am I missing a step?
trivial-rewrite resolves routing, smtp handles connection. relayhost isn’t available to smtp service, which means we need to work backward in the pipeline.
For this to work, sender_dependent_relayhost_maps must be set. This gets used by trivial-rewrite to determine next hop before injecting back into qmgr.
Note the use of brackets. This bypasses MX lookup for the named host. The value must explicitly match in smarthost-auth, including brackets and port if specified.
You may also remove the additional service in master.d/ unless custom concurrency limits outside relaylim service are desired.
The sender_dependent_relayhost_maps solution is what GPTs usually suggest, and can work in a simpler setup for sure but not in this case: the same relay host may need different credentials and I couldn’t find a way to instruct postfix to use the proper ones.
The additional services seem to be exactly what I need in this case. I managed to figure out a working config for Google:
Turns out you can be very specific with services, and setting smtp_sasl_password_maps can be exactly what I need since I can create different services pointing to different password maps to properly authenticate a specific domain/pool with a specific relay user.
Although it’s working and I have replicated the same thing on another node, I think I messed config partially and would like to reset to postfix base config. Do we have a scope for that?
Enable smtp_sender_dependent_authentication. In this setting the lookup key is the sender’s email rather than SMTP relay hostname. I’d imagine the same lookup treatment occurs: first the full email then @domain.
This has no effect. relayhost is used by trivial-rewrite, not smtp service.