I created a /etc/stunnel/stunnel.conf file based on the example file for a gmail tunnel (gmail-imap rule at
client = yes
accept = 184.108.40.206:143
connect = outlook.office365.com:993
verifyChain = no
whereas 220.127.116.11 is the IP address of the interface of the tunnel server.
Then I started stunnel with:
sudo service stunnel4 start
To check the tunnel is working, telnet to it:
$telnet 18.104.22.168 143
Connected to 22.214.171.124.
Escape character is '^]'.
* OK The Microsoft Exchange IMAP4 service is ready. [VgBJADEAUABSADAANwBDAEEAMAAxADcAMQAuAGUAdQByAHAAcgBkADAANwAuAHAAcgBvAGQALgBvAHUAdABsAG8AbwBrAC4AYwBvAG0A]
* BYE Microsoft Exchange Server 2016 IMAP4 server signing off.
A1 OK LOGOUT completed.
Connection closed by foreign host.
With this output we confirm the TLS tunnel is indeed working properly.
We also tested it with an Outlook Windows client pointed to 126.96.36.199:143 before pointing the application to the tunnel. It works well.
Adenda for begginers: why this works? Because most of the "new" secure Internet protocols are built using the old plaintext protocols with an added layer of encryption.