I've had the same configuration for years and a few days ago it suddenly stopped working. I double and triple checked settings both in gmail control panel (imap allowed, etc) and the mail account itself (imap.gmail.com, port 993, username/password, etc). I've also tried installing standalone Mail and it still doesn't work. I've enabled logging and all I get is a bunch of
29/05-2018 17:39:57 IMAP#1/1: Connecting... 29/05-2018 17:40:39 IMAP#1/1: Disconnected: Connection closed by server, unexpected disconnect
I have another email account configured in Opera Mail and it works fine.