We have a server that needs to connect to an IMAP server outside of our network.

Unfortunately, the server we need to connect to requires a connection on port 993. The problem is our host blocks port port 993 going in or out.

The option I am exploring, if it is even an option at all, is whether or not we can set up a relay that we can use to connect to the external IMAP server.

Say we set up an IMAP server listening on port 499 on another host we control, and then forward that traffic to the other IMAP server on port 993. Is that possible or an option? I have not much experience with relays, and may be completely off base.

  • 3
    What you need to be doing is yelling very loudly at your "host" until they fix the problem. – Michael Hampton Feb 7 '18 at 3:04

What you can do is a tunnel (port forwarding) or SOCK proxy. This is something ssh can do. Then you might want to have something like autossh to monitor an ssh tunnel and restart it as needed. Using ssh key pairs will allow you authentication without having to enter password

You can try this

ssh -L 499:your.imap.server:993 user@your.proxy.server

then you'll be able to see your.proxy.server:993 on your localhost:499 By default the port will not be exposed to external network interfaces unless you add the option -g Allows remote hosts to connect to local forwarded ports.

You can also set up a SOCK proxy (if your client is able to use it)

ssh -D 1234 user@your.proxy.server

Then set up your network connection to use it as a SOCK v4 on port 1234. To your host all outgoing connections will be seen as a ssh (probably port 22) to your.proxy.server.

| improve this answer | |
  • Is the proxy server the proxied server (upstream/target) imap server? – Barry Chapman Feb 7 '18 at 14:52
  • no, doesn't have to be. The first exemple requires one port per proxyed service, the second (SOCK) can proxy any tcp service anywhere your.proxy.server can reach (you will appear to the outer world as if you where on that host in both cases) – Antony Gibbs Feb 8 '18 at 9:51
  • and if your proxy is your target it's commun to see it written ssh -L 499:localhost:993 user@your.imap.server – Antony Gibbs Feb 8 '18 at 9:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.