Archived Forum Post

Index of archived forum posts


Error messages when logging into some Imap accounts

May 29 '17 at 17:27


I've got really very odd problem: one customer of mine has a lot of accounts which he wants to archive into my application. In the current version I log into the Imap accounts synchronously and everything works fine. For an upcoming version I'm changing to use asynchronous tasks. Where some but not all accounts give error messages like the one below. He gave me the login details for one account and when I try to log in everything works. The simplified code is below as well as the error from the plugin.

Any ideas what might cause this problem?

Xojo 2017r1, Mac OS 10.11. Chilkat .

Mit freundlichen Grüßen/Regards

Beatrix Willius Mail Archiver X: The email archiving solution for professionals


CkoImap.Port = Port
CkoImap.AuthMethod = "LOGIN"

if doSSL then CkoImap.Ssl = True call CkoImap.StartTls end if

'connect to server dim CkoConnectTask as Chilkat.Task = CkoImap.ConnectAsync(ServerName) call CkoConnectTask.Run While not CkoConnectTask.Finished CkoConnectTask.SleepMs(10) Wend

if not CkoConnectTask.TaskSuccess then globals.theErrorLog.LogItem(CurrentMethodName + " connect task didn't finish") Return "loginfailed" end if

dim theResult as Boolean = CkoConnectTask.GetResultBool if not theResult then globals.theErrorLog.LogItem "connection failed: " + getLastError if Verbose then globals.theErrorLog.LogItem getVerboseLog Return "loginfailed" end if

'login with user and password 'theResult = CkoImap.Login(UserName, Password) dim CkoLoginTask as Chilkat.Task = CkoImap.LoginAsync(UserName, Password) call CkoLoginTask.Run While not CkoLoginTask.Finished CkoLoginTask.SleepMs(10) Wend

if not CkoLoginTask.TaskSuccess then globals.theErrorLog.LogItem(CurrentMethodName + " login task didn't finish") Return "loginfailed" end if

theResult = CkoLoginTask.GetResultBool if theResult then ImapInfoOkay = True if Verbose then globals.theErrorLog.LogItem getVerboseLog Return "success" else globals.theErrorLog.LogItem "login failed: " + getLastError ImapInfoOkay = False if Verbose then globals.theErrorLog.LogItem getVerboseLog Return "loginfailed" end if


connection failed: ChilkatLog:
    DllDate: Jan 24 2017
    UnlockPrefix: BEATRX.xxxx
    Architecture: Little Endian; 32-bit
    Language: MAC OS X C/C++
    VerboseLogging: 1
    Component successfully unlocked using purchased unlock code.
        port: 143
            port: 143
            ssl: 0
              port: 143
              connectTimeoutMs: 30000
                Single-threaded domain to IP address resolution
                connecting to IPV4 address...
                  Setting SO_SNDBUF size
                  sendBufSize: 262144
                  Setting SO_RCVBUF size
                  recvBufSize: 4194304
                  Waiting for the connect to complete...
                  myPort: 52599
                  socket connect successful.
        Turning on TCP_NODELAY.
          SO_SNDBUF: 262332
          SO_RCVBUF: 4194536
          TCP_NODELAY: 4
          SO_KEEPALIVE: 8
        ConnectionType: Unencrypted TCP/IP
        numBytesRequested: 2048
        Connection closed by peer.
          error on socket shutdown.
          socketErrno: 57
          socketError: Socket is not connected
        nReceived: 0
        getImapResponseLine: Socket connection closed.
        Failed to get greeting.
      connect failed.

2017-05-13, 10:19:05 PM

Connecting to IMAP server at

----ERROR---- Failed to get command response on socket ----ERROR----


This section of code is suspect:

if doSSL then
CkoImap.Ssl = True
call CkoImap.StartTls
end if

StartTls is a property, not a method, so I would expect it to be like this:

if doSSL then
CkoImap.Ssl = True
CkoImap.StartTls = True
end if

However.. Ssl and StartTLS should never BOTH be True. The Ssl indicates that the connection is implicit SSL/TLS (typically port 993). Implicit TLS performs the TLS handshake immediately upon connecting.

The StartTls property indicates that a regular TCP connection is initially established (port 143 is typical). Then, prior to authentication, the IMAP client issues a "STARTTLS" command to convert the connection to TLS. Chilkat does this automatically when the StarTls property = True. For this particular server, you would want Ssl = False, but StartTls = True.

The behavior you see is that Chilkat is doing implicit TLS (because Ssl = True). The connection to port 143 is etablished, and Chilkat immediately begins the TLS handshake, but the IMAP server is not expecting it. The binary TLS handshake bytes being sent by Chilkat are unintelligible to the IMAP server, and it disconnects..


Thanks for the answer.

This particular code is not executed because the connection is on port 143 so DoSSL should be false. I also don't understand why this works in version 4.1 of my app but not for 4.2 which uses the same settings for SSL.

Obviously I need to read up on SSL. What is the correct code? Do I need to do testing what the different servers expect? Should I simply take out the line

CkoImap.StartTls = True


Mit freundlichen Grüßen/Regards

Beatrix Willius Mail Archiver X: The email archiving solution for professionals


Any news on this? I know the problem doesn't make sense. But this is what we see.


Beatrix Willius


Port 143 is the non-SSL/TLS port for IMAP. Whereas port 993 is the implicit SSL/TLS port for IMAP.

If TLS is to be used, and the initial connection is to port 143, then you would want these settings:

if doSSL then
CkoImap.Ssl = False
CkoImap.StartTls = True
end if

If you connect to port 143, then the initial connection is non-encrypted. The StartTls property indicates to send the STARTTLS command immediately after connecting to negotiate the TLS connection. This is called "explicit TLS". Implicit TLS is when the TLS handshake occurs implicitly right after the connection is established.