I have exactly the same issue - IMAP connections fail. I have 2 Rackspace accounts and 2 Gmail accounts configured with Apple Mail - the problem happens with all 4. After a short period of time I can't make an IMAP connection. I first discovered this because I couldn't put items in the trash. When attempting to trash items there is a small 'Copying Message' displayed in the bottom left corner of Apple Mail. When IMAP connection is working properly this message pops up and goes away very quickly. When IMAP connections are not working this message is displayed for a minute or so before getting an error message that items cannot be moved to the trash and they are returned to the inbox (or whatever box they were in before I attempted to trash them).

It took me a while to figure out that this was only related to IMAP connections, as others have reported I don't have any problem making SMTP connections.

I initially suspected this was related to Apple Mail so I downloaded and installed Air Mail (a very good client, BTW), but I had the same problem. As others have also reported, quitting Apple Mail and restarting fixes the problem temporarily, and so does restarting the computer. I've also discovered that if you switch network connections the problem is also temporarily fixed.
I've tried every combination of settings: changing IMAP ports, SSL/non-SSL, hostnames, IPs, and I've tested on my work network and at home. I've also followed the steps others have posted whereby I've removed accounts, re-installed, I've even set up a brand new account and it has the same problems. It seems the only common component is El Capitan and my MacBook Pro (2015).
This is such a headache for me that I've started managing my mail in the web interfaces for Gmail and Rackspace mail, but I have such a lot of email I'm thinking of rolling back to Yosemite. I'll post an update if I decide to try that.
Anyone else find any other permanent solution rather than rolling back to Yosemite?
Thanks.