Ver Mensaje Individual
  #3  
Antiguo 16-09-2020
ArtPortEsp ArtPortEsp is offline
Miembro
 
Registrado: may 2018
Ubicación: Mexico
Posts: 151
Reputación: 6
ArtPortEsp Va por buen camino
hola, pues ahora ya no se que pasa, la aplicación ya no puede enviar correos con gmail, el código es el siguiente:

notas:
  • ya me asegure que la opcion de ALLOW LESS SECURE APPLICATIONS en Gmail estuviera activada
    en el programa principal incluyo las librerias
    Código:
                   xlinea:=ExtractFilePath(Application.ExeName);
                   if (not fileexists(xlinea+'\libeay32.dll')) or (not fileexists(xlinea+'\ssleay32.dll')) then
                   begin
                        MessageDlg('Las librerias SSL no estan presentes en la carpeta del ejecutable.'+#13+#10+''+#13+#10+'La capacidad de correo electronico del sistema no estara habilitada.', mtWarning, [mbOK], 0);
                        GVCORE := False;
                   end
                   else
                        IdSSLOpenSSLHeaders.Load;


Código:
          // Conexion con el servidor de correo
          ListBox2.Lines.clear;
          with SMTP do
          begin
               if Gemailmetodo = 'sslvTLSv1'  then IdSSLIOHandlerSocketOpenSSL1.SSLOptions.Method := sslvTLSv1;
               if Gemailmetodo = 'sslvTLSv2'  then IdSSLIOHandlerSocketOpenSSL1.SSLOptions.Method := sslvSSLv2;
               if Gemailmetodo = 'sslvTLSv23' then IdSSLIOHandlerSocketOpenSSL1.SSLOptions.Method := sslvSSLv23;
               if Gemailmetodo = 'sslvTLSv3'  then IdSSLIOHandlerSocketOpenSSL1.SSLOptions.Method := sslvSSLv3;

               IoHandler := IdSSLIOHandlerSocketOpenSSL1;

               // tipo de autenticacion
               if Gemailauth = 'Defecto' then AuthType := atDefault;
               if Gemailauth = 'Ninguna' then AuthType := atNone;
               if Gemailauth = 'SASL'    then AuthType := atSASL;


               //Si se requiere autenticación para el envío indicar usuario y contraseña
               Username := Gemailcuenta;
               Password := Gemailpassword;
               Host     := Gemailserver;

               //Usar TLS SLL para el envío
               if GemailSSL = 'TLS explícito'   then useTLS := utUseExplicitTLS;
               if GemailSSL = 'Sin soporte TLS' then useTLS := utNoTLSSupport;
               if GemailSSL = 'TLS implícito'   then useTLS := utUseImplicitTLS;
               if GemailSSL = 'TLS requerido'   then useTLS := utUseRequireTLS;
                                                               
               // Puerto de salida                             
               port := strtoint(Gemailpuerto);
          end;

          try
               Listbox2.Lines.Add(DateTimeToStr(now)+' conectando con el servidor de correo ['+Gemailserver+']');
               SMTP.Connect;
               Listbox2.Lines.Add(DateTimeToStr(now)+' conectado con el servidor de correo');
          except
               on e : exception do
               begin
                    Listbox2.Lines.add(DateTimeToStr(now) + ' Error al conectar al servidor de correo ' + e.ClassName + ' ' + e.Message);
                    MessageDlg('Error al conectar con servidor SMTP: ' + e.Message, mtError, [mbok], 0);
               end;
          end;

          if SMTP.Connected then
          begin

               // Composicion del correo
               eMessage.Body.Assign(Etexto.Lines);
               eMessage.From.Text := Ede.text;
               eMessage.Recipients.Clear;
               x:= epara.text;

               If Ansipos(';',x) > 0 Then
               begin
                    While Ansipos(';',x) > 0 Do
                    begin
                         eMessage.Recipients.Add.Address:=Copy(x,1,Ansipos(';',x)-1);
                         x:=Copy(x,Ansipos(';',x)+1,999);
                    end;          { while }
                    eMessage.Recipients.Add.Address:=x;
               end
               else
                    eMessage.Recipients.Add.Address:=Epara.Text;

               eMessage.Subject := easunto.Text;

               If Efile.FileName <> '' then TIdAttachmentFile.Create(eMessage.MessageParts,Efile.FileName);

               Emessage.Priority := TidmessagePriority(mpHighest);

               Try
                    if Fcorreo.tag <> 7 then
                    begin
                         SMTP.Send(Emessage);
                         DM.Bitacora('Correo','Envio de correo electronico', '',' Destinatario ('+Epara.text+')');

                         if ladjuntos.Items.Count > 0 then MessageDlg('El correo y sus adjuntos fueron enviados correctamente',mtInformation,[mbOk],0)
                         else MessageDlg('El correo fue enviado correctamente',mtInformation,[mbOk],0);

                         //DeleteFile(Efile.FileName);
                    end
                    else
                         Fcorreo.Tag := 0;

                    if SMTP.Connected then SMTP.Disconnect;
               except
                    on e : exception do
                    begin
                         Listbox2.Lines.add(DateTimeToStr(now) + ' Error al enviar mensaje. ' + e.ClassName + ' ' + e.Message);
                         MessageDlg('Error al enviar e-mail: ' + e.Message, mtError, [mbok], 0);
                         if SMTP.Connected then SMTP.Disconnect;
                    end;
               end;
          end
          else
               MessageDlg('No fue posible conectar con el servidor de correo', mtError, [mbOK], 0);
gracias de antemano por su ayuda.
Responder Con Cita