3
votes

I've written a Windows service in Delphi 2007 using Indy 10 (10.5.8.0) that connects to an email server via IMAP and reads 10 emails, processes them and disconnects. This is repeated throughout the day. This works fine as long as the service doesn't connect using SSL/TLS.

When connecting using TLS it seems to work the first time, but gives a "start SSL negotiation failed" error on subsequent attempts. I'm using the following Indy settings in my service:

FIMAP4.Port := 143
FIMAP4.UseTLS := utUseRequireTLS;
FIdSSLIOHandlerSocketOpenSSL1.SSLOptions.Method := sslvSSLv23;

The email server runs Exchange 2010 and operates TLS on port 143 and SSL on port 993. I'm using the latest version of the ssl dlls (1.0.1.3).

I'm disconnecting by doing:

FIMAP4.IOHandler.InputBuffer.Clear;
FIMAP4.Disconnect;

UPDATE:

Extract from EurekaLog:

|IdExplicitTLSClientServerBase.pas|TIdExplicitTLSClient|TLSNotAvailable   |416[4]  |
|IdExplicitTLSClientServerBase.pas|TIdExplicitTLSClient|TLSNotAvailable   |412[0]  |
|IdExplicitTLSClientServerBase.pas|TIdExplicitTLSClient|ProcessTLSNotAvail|342[2]  |
|IdExplicitTLSClientServerBase.pas|TIdExplicitTLSClient|ProcessTLSNotAvail|341[1]  |
|IdIMAP4.pas                      |TIdIMAP4            |Login             |1957[16]|
|IdIMAP4.pas                      |TIdIMAP4            |Connect           |2019[28]|

This would seem to indicate TLS is NOT available (I would have expected TLSNotAvailable to raise a

EIdTLSClientTLSNotAvailable.Create(RSTLSSLSSLNotAvailable); 

rather than a

EIdTLSClientTLSNotAvailable.Create(RSTLSSLSSLCmdFailed);

but this has led me to wonder if the email server does not support TLS, at least on port 143).

If I don't use TLS, I get a: EIdReplyIMAP4Error: Command received in Invalid state.

|IdReplyIMAP4.pas   |TIdReplyIMAP4   |RaiseReplyError               |242[1]  |
|IdTCPConnection.pas|TIdTCPConnection|RaiseExceptionForLastCmdResult|576[1]  |
|IdIMAP4.pas        |TIdIMAP4        |Login                         |1970[29]|
|IdIMAP4.pas        |TIdIMAP4        |Connect                       |2019[28]|

This seems to be an authentication failed message, although I'm not sure why.

3

3 Answers

1
votes

Try using sslvTLSv1 instead of sslvSSLv23.

1
votes

Fixed!

Two critical settings were wrong:

FIdSSLIOHandlerSocketOpenSSL1.SSLOptions.Method := sslvTLSv1;
FIMAP4.UseTLS := utUseImplicitTLS;

setting these up (still on port 143) resolved the issue.

0
votes

The latest Indy 10 version works much better at TLS, SSL, IMAP, SMTP, and SASL, than the one that shipped in Delphi 2007. Heck, Delphi 2007 shipped in 2006 at some point, and so the Indy 10 version is a snapshot from 2006, that's SIX YEARS AGO.

Upgrade your Indy10 sources, and then try different SSL options.

You may also have a bad SSL (ssleay, libssl) DLL version. Use the versions recommended on the Indy page.