How to fix Lion 10.7 Apple Webmail "Connection to IMAP server failed"?
The Apple Webmail "Connection to IMAP server failed" error kept re-appearing, I changed /usr/share/webmail/config/appleoverrides.inc.php to:

$rcmail_config['default_host'] = 'localhost';
//$rcmail_config['smtp_server'] = '%h';


Idea from

Change in /usr/share/webmail/config/appleoverrides.inc.php the value of rcmail_config['default_host'] from its default 'tls://%h' to 'tls://macserver.examle.com'.

source: https://discussions.apple.com/message/16922962