3

I have some code written in Lazarus/FreePascal that uses the Synapse IMAPSend library unit. I attempt to login to an IMAP server over SSL (IMAPS) but the call to Login fails.

I've tried checking for exceptions - none are thrown.

Wireshark shows nothing beyond a TCP three-way handshake to the appropriate server and port.

Here's the code

function GetImapResponse(host, port, user, pass:String): String;
var
  response: String = '';
  imap: TIMAPSend;
  no_unseen: integer;
begin
  imap := TIMAPSend.create;
  try
    imap.TargetHost := host;  //'10.0.0.16';
    imap.TargetPort := port;  //'993';
    imap.UserName := user;    //'red';
    imap.Password := pass;    //'********';
    imap.AutoTLS := false;
    imap.FullSSL := true;
    response := response + 'IMAP login to '+user+'@'+host+':'+port+' ... ';
    if imap.Login then
    begin
      response := response + 'Logged in OK. ';
      // How many unseen?
      no_unseen := imap.StatusFolder('INBOX','UNSEEN');
      Form1.Label2.Caption := IntToStr(no_unseen);
      response := 'INBOX contains ' +  IntToStr(no_unseen) + ' unseen messages. ';
    end
    else
    begin
      response := response + 'IMAP Login failed. ';
    end;
  except
    on E: Exception do
    begin
      response := response + 'Exception: ' + E.Message;
      showMessage(response);
    end;
  end;
  {
  finally
    imap.free;
    response := response + 'Finally. ';
  end;
  }
  Result := response;
end;               

Here's the String result of this function

IMAP login to red@10.0.0.16:993 ... IMAP Login failed. 

Question: Is there a way to see some details of what IMAPSend thinks happened?


Update 1

As shown in SimaWB's answer plus comments by Arioch 'The

  mySynaDebug := TsynaDebug.Create;
  imap.Sock.OnStatus := @MySynaDebug.HookStatus;
  imap.Sock.OnMonitor := @MySynaDebug.HookMonitor; 

produced a projectname.slog file containing

20130722-103643.605 0011F230HR_SocketClose: 
20130722-103643.609 0011F230HR_ResolvingBegin: 10.0.0.16:993
20130722-103643.620 0011F230HR_ResolvingEnd: 10.0.0.16:993
20130722-103643.623 0011F230HR_SocketCreate: IPv4
20130722-103643.628 0011F230HR_Connect: 10.0.0.16:993
20130722-103643.631 0011F230HR_Error: 10091,SSL/TLS support is not compiled!

So I am moving forward :-)

I do have libssl32.dll and libeay32.dll in my project folder but will check I have the right versions and have done the right things with the chicken entrails.


Update 2:

I was using the 64-bit version of Lazarus. The OpenSSL DLLs are 32-bit DLLs which Synapse's ssl_openssl unit loads dynamically. I installed the 32-bit version of Lazarus/FPC and now my IMAP/SSL client program compiles and works as expected.

It seems the current 64-bit Lazarus/FPC binary distribution (v1.0.10/2.6.2) cannot cross-compile to i386 (which I think might have helped).

RedGrittyBrick
  • 3,827
  • 1
  • 30
  • 51
  • synapse comes with sources. Press F7 (Trace Into) on `imap.Login` and debug it like you debug all other parts of your program. – Arioch 'The Jul 19 '13 at 14:54
  • FYI Strictly speaking, -> x86 doesn't work if doesn't have the extended type. Originally x86_64 had extended deprecated, so it counts as "not having it". PowerPC64->PowerPC32 goes fine, it is not a general 64->32 issue. – Marco van de Voort Jul 24 '13 at 12:45
  • I'm building 32bit application with Delphi 10 Seattle, but I'm getting the "10091,SSL/TLS support is not compiled!" message. Does anybody tested it with latest version of Delphi ? – Victor Zanella Dec 26 '16 at 16:48

3 Answers3

5

Did you try synadbg unit of Synapse?

imap := TIMAPSend.create;
imap.Sock.OnStatus := TSynaDebug.HookStatus;
imap.Sock.OnMonitor := TSynaDebug.HookMonitor;

Then the application create a log file with extension '.slog'. May be you can find more details in the log file.

SimaWB
  • 9,246
  • 2
  • 41
  • 46
  • 1
    That looks useful but the compiler complains `Error: Wrong number of parameters specified for call to "HookStatus"` so it thinks I'm **calling** rather than (say) **assigning a reference to** a procedure. I can't find any examples of this usage. :-( – RedGrittyBrick Jul 19 '13 at 15:50
  • Then `@imap.Sock.OnStatus := @TSynaDebug.HookStatus;` or `imap.Sock.OnStatus := @TSynaDebug.HookStatus;` ? – Arioch 'The Jul 19 '13 at 19:46
  • @Arioch'The: I can't fathom out a way to do this that doesn't fail with `unit1.pas(95,26) Error: Incompatible types: got "" expected ""` – RedGrittyBrick Jul 22 '13 at 09:29
  • 1
    then that means you should create an object of TSynaDBG type and take the method of the object, not of the class – Arioch 'The Jul 22 '13 at 09:31
  • @RedGrittyBrick: May be it can be about version differences. http://www.ararat.cz/synapse/doku.php/public:howto:debugsocket – SimaWB Jul 22 '13 at 09:33
  • @SimaWB: That seems plausible, though I thought I was using latest versions. Anyway Arioch's hint got it working. – RedGrittyBrick Jul 22 '13 at 09:42
  • AFAIR in Delphi that works. But FPC is more strict compiler, at least in default configuration – Arioch 'The Jul 22 '13 at 09:54
1

Same error in the .slog file on Ubuntu 64-bit was fixed with "sudo apt-get install libssl-dev" and including "ssl_openssl" in the uses section.

Goran M
  • 11
  • 1
0

The problem is here: imap.AutoTLS := false; imap.FullSSL := true; try to set true to false and false to true... and port should be 587