TL;DR: I'm trying to force postfix to route mail sent from local user to another local user to be routed to another server (relayhost). This should not apply to incoming mail from external to local.
I'm planning a mail server stack migration (new imap and new smtp on new hardware). For a limited time, some users will be routed to the current server while others will me gradually migrated to the new mail server.
The current server will be the one that does all the routing (also the one registered in DNS as MX). When an incoming mail is coming, the mail will be forwarded or not on the new server based on the recipient mail address. This is working fine.
I'm having problem with local outgoing email routing (migrated colleague trying to send mail to non-migrated colleague). If I do nothing, a migrated colleague sending an email to a non-migrated user would seen his mail to the future inbox of non-migrated user. So the non-migrated user would not receive this mail until I migrated him.
I would like new Postfix to route outgoing emails to relayhost
even if the mail is "local". The relayhost is the server listed in DNS as MX, so the routing would be the same as the one I use for incoming mail.
I played with the transport_maps, but this cause incoming mail to loop between the old and the new server. This is because transport_maps apply for all emails (including incoming from external), not just the one local user send. The routing should only apply to outgoing mail from local users, not for all mail.
main.cf:
transport_maps = hash:/etc/postfix/transport
transport:
domain.tld smtp:[old-smtp.domain.tld]
Sender dependent relayhost maps should do the job.
See the Postfix documentation