Recent

Author Topic: Indy10 TIdSMTP with SSL fails on RaspberryPi  (Read 465 times)

BosseB

  • Sr. Member
  • ****
  • Posts: 358
Indy10 TIdSMTP with SSL fails on RaspberryPi
« on: May 05, 2021, 04:15:59 pm »
I have ported a Delphi application (service non-gui type) to FreePascal 3.2.0/Lazarus 2.0.12 on a Raspberry Pi3 with Raspbian Linux and I am now checking all of the functionality.
Yesterday I found that the built-in emailing on certain events failed...

It turns out that the Indy10 TIdSMTP class when running through an SSL connection fails to load the SSL library...
It has been discussed here before, but I found that the "solution" to use FPC 3.2.0 seems not to apply to a RaspberryPi installation (as I said above I use 3.2.0)...

I get this in the logfile the application writes:
Code: Text  [Select][+][-]
  1. 20210505 04:40:37.612 ERROR: Exception during email send: Could not load SSL library.
  2. 20210505 04:40:37.613 ERROR: Failed to send start mail message
  3. 20210505 04:42:39.491 ERROR: Exception during email send: Could not load SSL library.
  4. 20210505 04:42:39.492 ERROR: Failed to send finish mail message


Below is an abbreviated version of the code:

Code: Pascal  [Select][+][-]
  1. function TSSRemoteServer.SendMailMessage(Subject: string; BodyText, AttachedFiles: TStrings;): boolean;
  2. var
  3.   IdSendMail: TIdSMTP;
  4.   IdMessage: TIdMessage;
  5.   SSLHandlerSmtp: TIdSSLIOHandlerSocketOpenSSL;
  6.   ...
  7. begin
  8.   Result := false;
  9.   IdSendMail := TIdSMTP.Create(NIL);
  10.   IdMessage := TIdMessage.Create(NIL);
  11.   SSLHandlerSmtp := TIdSSLIOHandlerSocketOpenSSL.Create(NIL);
  12.   try
  13.     try
  14.       IdSendMail.Host := FEmailServer;
  15.       IdSendMail.Port := FEmailPort; //Added 2021-05-05
  16.  
  17.       if FEmailAuth then
  18.       begin
  19.         IdSendMail.AuthType := IdSmtp.satDefault;
  20.         IdSendMail.UserName := FEmailUser;
  21.         IdSendMail.Password := FEmailPwd;
  22.       end
  23.       else
  24.       begin
  25.         IdSendMail.AuthType := IdSmtp.satNone;
  26.         IdSendMail.UserName := '';
  27.         IdSendMail.Password := '';
  28.       end;
  29.  
  30.       if FEmailSSL then  //Added 2021-05-05 to handle the encrypted email send
  31.       begin
  32.         IdSendMail.IOHandler := SSLHandlerSmtp;
  33.         IdSendMail.UseTLS := utUseImplicitTLS;
  34.         SSLHandlerSmtp.Port := FEmailPort;
  35.       end;
  36.       IdSendMail.MailAgent := 'Remote Server';
  37.       IdMessage.IsEncoded := true;
  38.       IdMessage.Subject := Subject;
  39.       IdMessage.From.Text := FEmailSender;
  40.       IdMessage.Body.Text := BodyText.Text;
  41.  
  42.       if AttachedFiles.Count > 0 then
  43.       begin
  44.         LogStd('Attachment count: ' + IntToStr(AttachedFiles.Count));
  45.         {Attach each file in the list to the message}
  46.         for i := 0 to AttachedFiles.Count -1 do
  47.         begin
  48.           sTmp := AttachedFiles[i];
  49.           if FileExists(sTmp) then
  50.             with TIdAttachmentFile.Create(IdMessage.MessageParts, sTmp) do
  51.             begin
  52.               ContentType := 'application/x-zip-compressed';
  53.             end;
  54.         end;
  55.       end;
  56.       {Now send}
  57.       LogStd('Message prepared, now send mail');
  58.       try
  59.         bSendOK := false;
  60.         IdSendMail.Connect;
  61.         if IdSendMail.Connected then
  62.         begin
  63.           try
  64.             IdSendMail.Send(IdMessage);
  65.             bSendOK := true;
  66.           finally
  67.             IdSendMail.Disconnect;
  68.           end;
  69.           if bSendOK then
  70.           begin
  71.             Result := true;
  72.             LogStd('Mail message sent. Subject: ' + Subject);
  73.           end;
  74.         end;
  75.       except
  76.         on E: Exception do
  77.           LogErr('Exception during email send: ' + E.Message);
  78.       end;
  79.     except
  80.       on E: Exception do
  81.         LogErr('Exception in TSSRemoteServer.SendMailMessage: ' + E.Message);
  82.     end;
  83.   finally
  84.     IdSendMail.Free;
  85.     IdMessage.Free;
  86.     SSLHandlerSmtp.Free;
  87.   end;
  88. end;
  89.  
--
Bo Berglund
Sweden

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 960
    • Lebeau Software
Re: Indy10 TIdSMTP with SSL fails on RaspberryPi
« Reply #1 on: May 05, 2021, 06:14:57 pm »
It turns out that the Indy10 TIdSMTP class when running through an SSL connection fails to load the SSL library...

I just answered your same post on Indy's forum.

In a nutshell, your Pi is using OpenSSL 1.1.1, which TIdSSLIOHandlerSocketOpenSSL does not support.  Try this experimental SSLIOHandler for OpenSSL 1.1.1 (I don't know if it works on Linux/Pi).
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

 

TinyPortal © 2005-2018