Recent

Author Topic: SSL Error: TSendMail  (Read 5225 times)

PINO72

  • Newbie
  • Posts: 6
SSL Error: TSendMail
« on: January 24, 2019, 08:31:56 pm »
Hola a todos.
Tengo una aplicación en la que utilizo la librería Synapse 40.1 + xmailer 1.0.0.0 para enviar correos electrónicos mediante la función TSendMail.

Al actualizar mi sistema operativo Raspbian Stretch (sudo update / upgrade) , ha dejado de funcionar y al intentar enviar correos me presenta el error "SSL Error : TSendMail".

La versión de openssl anterior era la 1.1.0f (mayo de 2017), la actualizada es la 1.1.0g (Noviembre 2018).

He instalado las librerías de desarrollo "openssl-dev" y sigue sin funcionar.
Versión Lazarus :1.8.4
Sistema Operativo : Raspbian Stretch (ARM Linux) sobre Raspberry PI 2b+
Synapse : 40.1 (Actualizada desde OnlinePackageManager)
xMailer 1.0.0.0 (Actualizada desde OnlinePackageManager)

Código utilizado:
Code: Pascal  [Select][+][-]
  1. procedure TwVisualizacion.EnviaMailUsuario(MailsUsuario : TStringList; Var Mensaje : TStringList);
  2. Var
  3.     Mail : TSendMail;
  4.  
  5. begin
  6.    Try
  7.     Mail:= TSendMail.Create;
  8.     Mail.Sender:= RegEmpresa.SenderSMTP;
  9.     Mail.Receivers.Text:= MailsUsuario.Text;
  10.     Mail.Subject:= 'Avisos ControlTemp 3.3';
  11.     Mail.Message.Text:= Mensaje.Text;
  12.     Mail.Smtp.UserName:= RegEmpresa.UserSMTP;
  13.     Mail.Smtp.Password:= RegEmpresa.PassSMTP;
  14.     Mail.smtp.Host:=RegEmpresa.ServerSMTP;
  15.     Mail.smtp.Port:= RegEmpresa.PuertoSMTP;
  16.     Mail.Smtp.FullSSL:= RegEmpresa.SSL_Connect;
  17.     Mail.smtp.AutoTLS:=RegEmpresa.AutoTS;
  18.     Mail.Smtp.Timeout:=5000;
  19.     mail.Smtp.Sock.SocksTimeout:=2000;
  20.  
  21.     Try
  22.       Mail.Send;
  23.     Except
  24.       AddEvent('No se ha podido enviar la alarma por e-mail.' + Mail.smtp.FullResult.Text);
  25.     end;
  26.     finally
  27.     Mail.Free;
  28.    end;
  29. end;    
  30.  

Os agradecería alguna pista ..

Muchas gracias de antemano.



bylaardt

  • Sr. Member
  • ****
  • Posts: 309
Re: SSL Error: TSendMail
« Reply #1 on: January 25, 2019, 02:42:40 am »
Yo uso esta función para enviar correo electrónico:
Code: Pascal  [Select][+][-]
  1. function MailSend(Const MailFrom,Replyto,SMTPHost,SMTPPort,user,password,MailTo, MailSubject,MailBody,Mailattachments,cripto: string): Boolean;
  2. var
  3.   SMTP: TSMTPSend;
  4.   sl:TStringList;
  5.   mime:TMimemess;
  6.   part: TMimepart;
  7.   x:integer;
  8.   anexo:TstringList;
  9.   error:string;
  10.   i,l:integer;
  11.   temp,MyMailTo,MailToSend:String;
  12.   mailSeparator:Char;
  13. begin
  14.   MailToSend:='';
  15.   i:=1;
  16.   MyMailTo:=trim(MailTo);
  17.   l:=Length(MyMailTo);
  18.   mailSeparator:=',';
  19.   while i<=l do begin
  20.     if MyMailTo[i] in [#1..#32,':',';','|',','] then begin
  21.       if (i>1) and (not(copy(MailToSend,length(MailToSend),1)=mailSeparator)) then
  22.         MailToSend:=MailToSend+mailSeparator;
  23.     end else
  24.       MailToSend:=MailToSend+MyMailTo[i];
  25.     inc(i);
  26.   end;
  27.   error:='';
  28.   Result:=False;
  29.   SMTP:=TSMTPSend.Create;
  30.   sl:=TStringList.Create;
  31.   mime:=TMimemess.create;
  32.   mime.Header.CharsetCode:=UTF_8;
  33.   sl.text:= SysToUTF8(MailBody);
  34.   part := mime.AddPartMultipart('mixed', nil);
  35.   mime.AddPartTextEx(sl,part,UTF_8,false,ME_BASE64);
  36.   Anexo:=TStringList.create;
  37.   anexo.text:=Mailattachments;
  38.   if anexo.Count>0 then begin
  39.     for x:=0 to anexo.count-1 do
  40.        mime.AddPartBinaryFromFile(anexo[x],part);
  41.     anexo.free;
  42.   end;
  43.   mime.header.subject:=SysToUTF8(MailSubject);
  44.   mime.header.from:=MailFrom;
  45.   mime.header.ReplyTo:=Replyto;
  46.   mime.Header.XMailer:=pb_SystemName;
  47.   mime.Header.Organization:='';
  48.   mime.EncodeMessage;
  49.   SMTP.UserName:=User;
  50.   SMTP.Password:=Password;
  51.   SMTP.TargetHost:=SMTPHost;
  52.   SMTP.AutoTLS:=cripto='TLS';
  53.   SMTP.FullSSL:=cripto='SSL';
  54.   SMTP.TargetPort:=SMTPPort;
  55.   if SMTP.Login then begin
  56.       result:=SMTP.MailFrom(Replyto, Length(mime.Lines.Text));
  57.       if result then begin
  58.         while result and (length(MailToSend)>0) do begin
  59.            temp:=trim(ExtractStrUtf8(MailToSend,mailSeparator));
  60.            if length(temp)>0 then
  61.              result:=SMTP.MailTo(temp);
  62.         end;
  63.         if result then begin
  64.           result:=SMTP.MailData(mime.lines);
  65.           if not result then
  66.             error:='MailData Error: '+smtp.ResultString;
  67.         end else error:='MailTo Error: '+smtp.ResultString;
  68.       end else error:='MailFrom Error: '+smtp.ResultString;
  69.       SMTP.Logout;
  70.   end else error:='Login Error: '+smtp.ResultString;
  71.   SMTP.Free;
  72.   sl.Free;
  73.   mime.free;
  74.   if (not result) and (length(trim(error))>0) then
  75.     raise Exception.Create(error)
  76.   else
  77.     DebugLn('Email','"'+MailSubject+'" enviado para "'+MailToSend+'".');
  78. end;
  79.  

PINO72

  • Newbie
  • Posts: 6
Re: SSL Error: TSendMail
« Reply #2 on: January 25, 2019, 07:23:35 pm »
Ante todo gracias por responder.

El problema no estaba en la función en sí, sospechaba que estaba en no tener instaladas las librerías de desarrollo para poder utilizar SSL y TLS (xmailer + sinapse 40.1).

Lo solucioné instalando el paquete "libssl1.0-dev".

Repito, gracias por responder y espero que le pueda servir a alguien que tenga el mismo problema.

 

TinyPortal © 2005-2018