Recent

Author Topic: XMailer + Synapse smtp TLS mail in Fedora 36 x86_64  (Read 413 times)

reneve59

  • New Member
  • *
  • Posts: 25
XMailer + Synapse smtp TLS mail in Fedora 36 x86_64
« on: September 22, 2022, 05:05:25 am »
Hi,

I'm working on a project that requires to send automatically a mail to webmaster every time a specific event happens on the web server. I've developed an external web monitor in Lazarus using XMailer - Synapse packages to create and send the mail message using SMTP and TLS

It works without problems under Windows 10 (64 bits) but not in Linux (Fedora 36 x86_64). Lazarus compiles the application without errors,  but when trying to send the mail the application reports an error

I found the problem, it is on synapse's ssl_openssl unit (it does not find openssl version under fedora) but I do not have any idea on how to fix it. I try to find the solution in the internet without luck. Must of it is outdated

Any idea?.

The application :

Code: Pascal  [Select][+][-]
  1. unit msend_main;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, Buttons,
  9.   StdCtrls, LCLType,
  10.   xmailer;
  11.  
  12. type
  13.  
  14.   { TForm1 }
  15.  
  16.   TForm1 = class(TForm)
  17.     Bevel1: TBevel;
  18.     btn_send: TBitBtn;
  19.     btn_Exit: TBitBtn;
  20.     Label1: TLabel;
  21.     lbl_subject: TLabel;
  22.     m_message: TMemo;
  23.     m_subject: TEdit;
  24.     m_sender: TEdit;
  25.     lbl_to: TLabel;
  26.     lbl_from: TLabel;
  27.     m_recipient: TEdit;
  28.     procedure btn_ExitClick(Sender: TObject);
  29.     procedure btn_sendClick(Sender: TObject);
  30.   private
  31.  
  32.   public
  33.  
  34.   end;
  35.  
  36. var
  37.   Form1: TForm1;
  38.  
  39. implementation
  40.  
  41. {$R *.lfm}
  42.  
  43. { TForm1 }
  44.  
  45. procedure TForm1.btn_ExitClick(Sender: TObject);
  46. begin
  47.   Close;
  48. end;
  49.  
  50. procedure TForm1.btn_sendClick(Sender: TObject);
  51. var Mail : TSendMail;
  52.     emsg : string;
  53. begin
  54.   Mail := TSendMail.Create;
  55.   try
  56.     //
  57.     // Mail data section
  58.     //
  59.     Mail.Sender        :=  m_sender.Text;
  60.     Mail.Receivers.Add(m_recipient.Text);
  61.     Mail.Subject       :=  m_subject.Text;
  62.     Mail.Message.AddStrings(m_message.Lines);
  63.     //
  64.     // Authentication section
  65.     //
  66.     Mail.Smtp.UserName := 'username';
  67.     Mail.Smtp.Password := 'userpswd';
  68.     //
  69.     // Mail parameters section
  70.     //
  71.     Mail.Smtp.Host     := 'server.example.com';
  72.     Mail.Smtp.Port     := '587';
  73.     Mail.Smtp.FullSSL  := False;
  74.     Mail.Smtp.TLS      := true;
  75.     //
  76.     // Semd mail
  77.     //
  78.     try
  79.       Mail.Send;
  80.       emsg := 'Mail processed correctly';
  81.       Application.MessageBox(@emsg[1],'Mail Sent',MB_OK + MB_ICONEXCLAMATION);
  82.       except
  83.         on e : exception do
  84.                begin
  85.                  emsg := 'Error: ' + e.Message;
  86.                  Application.MessageBox(@emsg[1],'Meil Error',MB_OK + MB_ICONERROR);
  87.                end;
  88.     end;
  89.   finally
  90.     Mail.Free;
  91.   end;
  92.  
  93. end;
  94.  
  95. end.
  96.  

[Edited to add code tags - Please use tags in future]
« Last Edit: September 22, 2022, 07:45:18 am by trev »

reneve59

  • New Member
  • *
  • Posts: 25
Re: XMailer + Synapse smtp TLS mail in Fedora 36 x86_64
« Reply #1 on: September 22, 2022, 02:40:41 pm »
Hi,

I have found a solution and now the program runs on Fedora 36 x86_64. I share the solution in case somebody has the same problem.

The solution:

Xmailer tests if openssl is available using a function called IsAvailableOpenSSL (starting at line 105 of XMailer's source file) and returns True if version string is not empty.

Code: Pascal  [Select][+][-]
  1. {$IFDEF OPEN_SSL}
  2. function IsAvailableOpenSSL: Boolean;
  3. var
  4.   VOpenSSL: TSSLOpenSSL;
  5. begin
  6.   VOpenSSL := TSSLOpenSSL.Create(nil);
  7.   try
  8.     Result := VOpenSSL.LibVersion <> '';
  9.   finally
  10.     VOpenSSL.Free;
  11.   end;
  12. end;
  13. {$ENDIF}
  14.  

As I'm sure that openssl library is installed in Fedora, I  modified Xmailer's code as follows

Code: Pascal  [Select][+][-]
  1. function IsAvailableOpenSSL: Boolean;
  2. var
  3.   VOpenSSL: TSSLOpenSSL;
  4. begin
  5.   VOpenSSL := TSSLOpenSSL.Create(nil);
  6.   try
  7. //    Result := VOpenSSL.LibVersion <> '';
  8.     Result := True;
  9.   finally
  10.     VOpenSSL.Free;
  11.   end;
  12. end;
  13. {$ENDIF}
  14.  

I rebuilt the application an now is running.

zeljko

  • Hero Member
  • *****
  • Posts: 1335
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: XMailer + Synapse smtp TLS mail in Fedora 36 x86_64
« Reply #2 on: September 22, 2022, 03:49:14 pm »
Fedora 36 uses openssl-3, so you should include openssl3 from synapse or install compat-openssl

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1998
  • Former Delphi 1-7, 10.2 user
Re: XMailer + Synapse smtp TLS mail in Fedora 36 x86_64
« Reply #3 on: September 23, 2022, 04:12:45 pm »
[Apropos of bypassing the library version check...]

The latest OpenSSL stable version is the 3.0 series which is supported until 7th September 2026. This is also a Long Term Support (LTS) version.

The previous LTS version OpenSSL 1.1.1 is on life support until 11th September 2023 (at which point all support ceases, so no bug fixes for security problems) as OpenSSL moves to version 3 (now at 3.02) which has even more significant ABI changes.

All older OpenSSL versions (including 1.1.0, 1.0.2, 1.0.0, 0.9.8 and 0.9.7) are now out of support, contain multiple security vulnerabilities and should not be used if you value security and your reputation.
« Last Edit: September 23, 2022, 04:14:17 pm by trev »
Lazarus 2.3, FPC 3.3.1 macOS 12.3.1 x86_64 Xcode 13.4
Lazarus 2.3, FPC 3.3.1 macOS 12.3.1 aarch64 Xcode 13.4

 

TinyPortal © 2005-2018