I had the same problem after going to Lion Server. What seemed to have been the problem was that I also recently exchanged my router, as lightning (sic!) struck my old Draytek. Now I have a Fritz!Box and that thing has limited configuration options for DNS.
So my situation -- which may or may not be what you have -- was that the internal fully-qualified name (what the server thinks it is based on its IP address and the reverse lookup the Fritz!Box gives is) and the external name are different.
So, if my server is called Lion, and my external (DynDNS-domain) is domain.me, then the server thinks it is Lion.fritz.box, but I address it via Lion.domain.me. And then the imap server, which listens on domain.me seems not to respond to being called fritz.box (or vice-versa, not sure what's really happening behind the scenes).
I solved it by setting up DHCP and DNS on the Lion server, making it name server for domain.me, and then switching off the DNS-service in the Fritz!Thingy. So in the intranet the Lion.domain.me is resolved to the 192.168.1.2 or so of the server, but if you're off-site, you get the DynDNS address for your router, which then sends stuff where it should go.
The you change the server network name (in that new Server application under Server->Network) from Lion.fritz.box to Lion.domain.me, ensure the SSL-certificates reflect the new name, and suddenly the IMAP and the Web-interface believe they are on the same machine.
Worked for me. Just tried also from my iPad via 3G, so coming in from the internet, and works like a charm. Too bad Apple have removed a lot of the configuration options in the new server management application, so this differing name problem is not so obvious and easily fixed.
Hope this helps! And if not, at least I can find my own solution back here in the forum should I ever need it again
Not sure, but I would think it should work if both names resolve to the same ip-address. So if you are using a dyndns service, update both records (mymachine... and www...) at the same time to your router's external ip address, resp. to your server's address from the intranet. That may work.
Else I guess you'd have to go into the webmail configuration files and figure out where Apple put the server name and manually fix it. I believe in Snow Leopard the problem did not exist, but 'm not sure anymore if anyone used the webmail interface after I installed that Fritz!Box, so we may never have noticed that it was broken.
In Server Admin goto Mail-->Settings and take a look at the SSL section. There is no point in setting SMTP SSL to Required because servers don't normally communicate with each other using SSL, if webmail is used and IMAP and POP SLL is set to required, you'll most likely get the message that the connection to the IMAP server failed. They should both be set to Use in most cases.
Hope this helps!
Solved! At least for me...
I have described all solutions to the major problems I've been having from a crippled 10.7.3 install to a flourishing one here:https://discussions.apple.com/message/17740033#17740033
Hope this helps!