I was using courier-imap and courier-pop until today. I've just installed the -ssl versions of both.
At install they both create a certificate for localhost based in New York. This doesn't work unless it really is localhost.
In /etc/courier there are imapd.pem, imapd.cnf, pop3d.pem and pop3d.cnf
Delete the .pem files
Edit the .cnf files - make sure that you set CN to be the hostname or the mail server
Run mkimapdcert
Run mkpop3dcert
Restart the services
I left the non-ssl IMAP running but only for 127.0.0.1 for squirrelmail.