Club Delphi  
    Paypal   FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > OOP
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Coloboración Paypal con ClubDelphi

 
 
Herramientas Buscar en Tema Desplegado
  #24  
Antiguo 12-09-2024
Avatar de Casimiro Noteví
Casimiro Noteví Casimiro Noteví is offline
Merodeador
 
Registrado: sep 2004
Ubicación: En algún lugar.
Posts: 32.669
Poder: 10
Casimiro Noteví Tiene un aura espectacularCasimiro Noteví Tiene un aura espectacular
Mira si te sirve de ejemplo:

Código Delphi [-]
// Es la función que nos permite enviar el Mail con Indy 10. 
// en la cabecera están definidos los parámetros 
function SendEmailIndy10(AEmailEnvio:string; AListaAdjuntos: TStringList; 
                         AHostSMTP: string; APortSMTP: Integer; 
                         AAsunto: string; ACuerpoMensaje: string; 
                         ANombreUsuario: string; APasswordUsuario: string; 
                         AFromText:string; 
                         AListaParametros:TStrings; 
                         AListaParamsDB:TStrings; 
                         AListaParamsIMG:TStrings; 
                         tls:TIdUseTLS; 
                         sslVersion:TIdSSLVersion; 
                         AFormatoPlano:boolean; 
                         var outMessage:String; 
                         procStatus:TidStatusEvent=nil): integer; 
var 
    ServidorSMTP: TIdSmtp; 
    sslHandler: TIdSSLIOHandlerSocketOpenSSL; 
    Mensaje: TIdMessage; 
    idText: TIdText; 
    i: Integer; 
    TS:TStrings; 
begin 
    // ini 
    Result := 0; 
    outMessage := ''; 
 
    // Creamos los objetos y componentes necesarios 
    ServidorSMTP := TIdSmtp.Create(nil); 
    sslHandler := TIdSSLIOHandlerSocketOpenSSL.Create(nil); 
    Mensaje := TIdMessage.Create(nil); 
 
    // proteccion para liberar 
    try 
        // Si la lista de paámetros está asignada, los sustituimos por los valores 
        if Assigned(AListaParametros) then begin 
          ACuerpoMensaje := SustituirParametros(ACuerpoMensaje, AListaParametros); 
        end; 
        // Si recibimos parámetros dinámicos de la BD, los sustituimos por los valores 
        if Assigned(AListaParamsDB) then begin 
          ACuerpoMensaje := SustituirParametros(ACuerpoMensaje, AListaParamsDB); 
        end; 
        // si recibimos alguna imagen en la lista, la sustituimos por sus urls 
        if Assigned(AListaParamsIMG) then begin 
          if not(AFormatoPlano) then  // si no es texto, sino que sí es html... 
            ACuerpoMensaje := SustituirParametrosImagen(ACuerpoMensaje, AListaParamsIMG); 
        end; 
        // 
        // Proteccion para liberar 
        try 
            // configuraciones básicas para el server SMTP 
            ServidorSMTP.Host := AHostSMTP; 
            ServidorSMTP.Port := APortSMTP; 
            ServidorSMTP.Username := ANombreUsuario; 
            ServidorSMTP.Password := APasswordUsuario; 
 
            // Timeout; Necesario para algunas versiones de las Indy 
            ServidorSMTP.ReadTimeout := 30000; 
 
            // Procedimientos de Callback (opcionales) 
            ServidorSMTP.OnStatus := procStatus; 
 
            //·································································· 
            // Podríamos llegar a usarlos, pero no es necesario... de momento 
            // ServidorSMTP..OnConnected :=IdSMTP1Connected; 
            // ServidorSMTP..OnDisconnected :=IdSMTP1Disconnected; 
            // ServidorSMTP..OnFailedRecipient :=IdSMTP1FailedRecipient; 
            // ServidorSMTP..OnStatus :=IdSMTP1Status; 
            // ServidorSMTP..OnTLSNotAvailable :=IdSMTP1TLSNotAvailable; 
            // ServidorSMTP..OnWork :=IdSMTP1Work; 
            //·································································· 
 
            // Cambios segun si el server soporta o no TSL 
            if (tls <> utNoTLSSupport) then 
            begin   // Valores estandard 
              sslHandler.Destination := AHostSMTP + ':' + IntToStr(APortSMTP); 
              sslHandler.Host := AHostSMTP; 
              sslHandler.Port := APortSMTP; 
              sslHandler.SSLOptions.Method := sslVersion; 
              sslHandler.ReadTimeout := 30000; 
              ServidorSMTP.IOHandler := sslHandler; 
              ServidorSMTP.UseTLS := tls; 
            end; 
 
            // Configuración básica del mensaje 
            Mensaje.From.Address := ANombreUsuario; 
            Mensaje.From.Text := AFromText; 
            Mensaje.Recipients.EMailAddresses := AEmailEnvio; 
            Mensaje.Subject := AAsunto; 
            Mensaje.ContentType := 'multipart/mixed'; 
 
            // Preparamos lo necesario para "montar" el cuerpo del mensaje 
            TS := TStringList.Create(); 
            // protección para liberar 
            try 
              TS.Text := ACuerpoMensaje; 
 
              // Si estamos en modo texto? 
              if (AFormatoPlano) then begin 
                idText := TIdText.Create(Mensaje.MessageParts, TS); 
                idText.ContentType := 'text/plain'; 
              end 
              else begin 
                idText := TIdText.Create(Mensaje.MessageParts, TS); 
                idText.ContentType := 'text/html'; 
                idText.ContentTransfer := '7bit'; 
                Mensaje.ContentTransferEncoding := 'text/html'; 
              end; 
            finally 
              FreeAndNil(TS); 
            end; 
 
            // Asignada la lista de ficheros Adjuntos? 
            if Assigned(AListaAdjuntos) then begin 
              // recorer la lista y añadir los ficheros... 
              for i := 0 to (AListaAdjuntos.Count - 1) do begin 
                // si existe, lo añadimos... 
                if FileExists(AListaAdjuntos[i]) then begin 
                  TIdAttachmentFile.Create(Mensaje.MessageParts, AListaAdjuntos[i]); 
                end; 
              end; 
            end; 
 
            // proteccion para la conexion 
            try 
              ServidorSMTP.Connect;                          // PASO 1: conexion 
              // proteccion para el envio 
              try 
                ServidorSMTP.Send(Mensaje);                 // PASO 2 : envío 
                //-Debug- showmessage('El mensaje se envió correctamente'); 
                Result := Result + ID_ENVIO_OK;  // OK 
              except 
                on E:Exception do begin 
                  //-Debug- showmessage('Se produjo un fallo durante el envío del mensaje; ' + sLineBreak + E.Message); 
                  Result := ID_ENVIO_ERROR_ENVIO {-20}; 
                  outMessage := rsErrorAlEnviar + E.Message; 
                end; 
              end; 
            except 
              on E:Exception do begin 
                //-Debug- showmessage('Se produjo un fallo durante la conexión con el servidor; ' + sLineBreak + E.Message); 
                Result := ID_ENVIO_ERROR_CONEXION {-10}; 
                outMessage := rsErrorAlConectar + E.Message; 
              end; 
            end; 
 
            //si nos hemos conectado correctamente, al finalizar, desconectamos,... 
            if (ServidorSMTP.Connected) then begin 
              ServidorSMTP.Disconnect;                    // PASO3: desconexion 
            end; 
        finally 
          // Liberar los componentes creados 
          Mensaje.Free; 
          sslHandler.Free; 
          ServidorSMTP.Free; 
        end; 
      except 
        // en caso de excepción "desconocida" devolvemos esto... 
        on E:exception do begin 
          Result := -1; // desconocido 
          outMessage := rsErrorDesconocido + E.Message; 
        end; 
    end; 
end;
Responder Con Cita
 



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Envio de correos SIN SSL Rc96 Internet 4 15-09-2017 19:42:58
?Envio de correos ? jasmad Lazarus, FreePascal, Kylix, etc. 16 02-10-2012 15:45:02
Error Al Obtener el Body de correos electronicos con Indy9 Enan0 Internet 1 27-01-2010 15:59:43
Envio de Correos Masivo Esau Internet 2 10-04-2007 01:46:11


La franja horaria es GMT +2. Ahora son las 06:05:07.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi