What you're looking for is a reverse proxy, or in this case, a TCP reverse proxy. I believe only NGINX plus (paid?) supports that. You're probably better off using haproxy.
I haven't done it so I can't help in that front, but I found this: https://www.linuxbabe.com/mail-server/smtp-imap-proxy-with-haproxy-debian-ubuntu-centos
Which is close to your scenario (I just looked at the first result). Otherwise the search term "haproxy imap" or "haproxy mail server" may help you find something, maybe throwing in wireguard or VPN.