Connect to Imap server with SSLSocket

How do I verify that I can connect to an Imap server via SSLSocket? I’ve modified the example “SynchronousTCPSocketExample.xojo_binary_project” for SSLSockets. But if I want to connect to “imap.mail.yahoo.com” with port 993 I only get error 103. Changing the connectiontype didn’t change anything.

[code]dim socket as new SSLSocket

’ set it’s port and address
socket.Address = AddressField.Text
socket.Port = Val(PortField.Text)
'Socket.connectiontype = SSLSocket.TLSv1

socket.Connect

// while the socket isn’t connected
While Not socket.SSLConnected
// check to see if the socket got an error
If socket.LastErrorCode <> 0 Then
Output("Socket Error: " + Str(socket.LastErrorCode))
Exit
End
// poll the socket to let it do it’s thing
socket.Poll
Wend

// if we broke the loop because we’re connected
If socket.SSLConnected Then
Output("Socket Connected.)
Else
// The socket broke out of the loop due to an error
Output(“Socket never connected.”)
End If

socket.Close[/code]

and if you type “https://” before the imap server address ?

@jean-yves pochez : I want to connect to imap. But I tried anyway with https and it makes a nice infinite loop.

I just tried the xojo example you say, connect to “imap.mail.yahoo.com” with port 993 and it gets connected in 5 ms
no socket error
but it is the original example with tcpsocket and not the sslsocket you’re using

Thanks for testing. But this doesn’t work for me. I still get the error 103. Strange…

Time to do something else for now.

Error 103 is a name resolution error. Are you sure you are pointing to the correct server?

Have been wondering about this myself. But Jean-Yves was able to connect and I simply copied the server name over from my Mail account. In Python when connecting with imaplib I get

for res in _socket.getaddrinfo(host, port, family, type, proto, flags):

socket.gaierror: [Errno 8] nodename nor servname provided, or not known

I’m rather sure that this worked - once upon a time. Is the Yahoo version of “too many logins”?

Hi Beatrix,

When using the original code you posted, I also get the 103 error.

When using Jean-yves pochez’s suggestion it connects. Here is modified code which seems to work.

[code] Dim socket As New TCPSocket 'changed to TCPSocket

’ set it’s port and address
socket.Address = “imap.mail.yahoo.com
socket.Port = 993
'Socket.connectiontype = SSLSocket.TLSv1

socket.Connect

// while the socket isn’t connected
While Not socket.IsConnected 'changed
// check to see if the socket got an error
If socket.LastErrorCode <> 0 Then
System.DebugLog("Socket Error: " + Str(socket.LastErrorCode))
Exit
End
// poll the socket to let it do it’s thing
socket.Poll
Wend

// if we broke the loop because we’re connected
If socket.IsConnected Then 'changed
System.DebugLog(“Socket Connected.”)
Else
// The socket broke out of the loop due to an error
System.DebugLog(“Socket never connected.”)
End If

socket.Close[/code]

@Eugene: thanks, that works. Except for §$%& Yahoo. I can’t even ping the server.

@Beatrix Willius - I notice in your original code that you have the ConnectionType commented out. In the current released version of Xojo, this defaults to SSLv23 which means that it tries SSLv3 first and then falls back to SSLv2. Your code most likely worked until the POODLE vulnerability was publicized this fall… I think you’ll find that with the other improvements here, that if you set that ConnectionType to TLSv1, it’ll work a lot better.

FWIW, we have updated the default value of ConnectionType to TLSv1 for the next version of Xojo, so this shouldn’t be an issue going forward.

@Greg: the line was commented out because I had tried all three values. Actually, I need the check if I can connect to the Imap server via SSL for the Poodle:

  1. Connections for TLS need to be instantiated without SSL and then STARTTLS is used for encrypting.
  2. I’ve got problems with Python handling exceptions and so I thought that I could do the easy stuff in Xojo.

But Yahoo is kaputt anyhow. For now I’m trying to connect via TCP socket and if I can’t then I know that it’s SSL.