How to use SMTP and IMAP with iCloud email?
Interestingly I had a similar problem last night, and I have been using iCloud for some time now. I suspect it was caused by the live switch on iCloud. I simply went to the iCloud preference panel, logged out and logged back in. The new terms and conditions was shown, I accepted, restarted Mail and everything was working.

I suggest trying this first, because manually configuring it can cause problems in future should Apple decide to make changes to the routes.

The IMAP setting for iCloud is available in this Apple support document.