I've finally found what was causing the problem. It was mainly the webmail like you mentioned. The webmail was using the IMAP ports and that's why Thunderbird couldn't connect because it was already used by the webmail. If I disable webmail completly, then the Thunderbird can even recognise the server settings for himself and it is working nicely with STARTTLS.