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 [email protected]: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).

3
  • synapse comes with sources. Press F7 (Trace Into) on imap.Login and debug it like you debug all other parts of your program. Jul 19, 2013 at 14:54
  • FYI Strictly speaking, <n> -> x86 doesn't work if <n> 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. Jul 24, 2013 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 ? Dec 26, 2016 at 16:48

3 Answers 3

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.

7
  • 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. :-( Jul 19, 2013 at 15:50
  • Then @imap.Sock.OnStatus := @TSynaDebug.HookStatus; or imap.Sock.OnStatus := @TSynaDebug.HookStatus; ? Jul 19, 2013 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 "<class method type of procedure(TObject,THookSocketReason,const AnsiString) of object;Register>" expected "<procedure variable type of procedure(TObject,THookSocketReason,const AnsiString) of object;Register>" Jul 22, 2013 at 9:29
  • 1
    then that means you should create an object of TSynaDBG type and take the method of the object, not of the class Jul 22, 2013 at 9:31
  • @RedGrittyBrick: May be it can be about version differences. ararat.cz/synapse/doku.php/public:howto:debugsocket
    – SimaWB
    Jul 22, 2013 at 9:33
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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.