SMTP & IMAP proxy based on domain (pass-through)

No, this is not really possible, because you have to support a) cleartext and b) STARTTLS, neither allows SNI based routing decisions, because the SNI value, if it exist at all, is not in the first packet.

You can only do this with implicit TLS, meaning imaps on TCP Port 993 and SMTP submission with implicit TLS on port 465.

Port 587 is unencrypted until you start the TLS session with STARTTLS. It’s therefor impossible to route based on SNI.

I don’t think SNI contains the domain. It usually contains the hostname you are connecting to.

I’m also not sure if MUA’s really do SNI, and if it’s supported widely enough so that it’s actually usable.