Tema: IdSmtp
Ver Mensaje Individual
  #14  
Antiguo 09-12-2005
elguille elguille is offline
Miembro
 
Registrado: ene 2005
Posts: 114
Reputación: 20
elguille Va por buen camino
Resumo todo lo dicho con una funcion que funciona (comprobado)

añadir a USES

IdBaseComponent, IdComponent, IdTCPServer, IdSMTPServer,
IdMessage, IdEMailAddress, IdTCPConnection, IdTCPClient, IdMessageClient, IdSMTP,idexception

Código Delphi [-]
  procedure email2(host:string;nombre:string;password:string;port:integer;desde:string;
    hasta:string;asunto:string;cuerpo:string;adjunto:string);
  var
      IDSMTP1: TIDSMTP;  // Componente de envio de correo
      mensaje: TIdMessage;
  begin
  IDSMTP1:=TIDSMTP.Create(nil);
  IdSMTP1.AuthenticationType :=atLogin;
  IdSMTP1.UserNAME := nombre;
  IdSMTP1.Password := password;
  IdSMTP1.Host := host;
  IdSMTP1.Port := port;
  MENSAJE:=TIDMESSAGE.CREATE(nil);
  with Mensaje do
  begin
  Body.Add(CUERPO);
  From.Text := desde;
  Recipients.EMailAddresses := hasta;
  Subject := asunto;
  Priority := TIdMessagePriority(mpHighest);//prioridad del mensaje
  CCList.EMailAddresses := '';
  BccList.EMailAddresses := '';
  TIdAttachment.Create(Mensaje.MessageParts,adjunto);
  end; //configuracion server smtp
  with idsmtp1 do
  begin
   try
      Connect;
      try
        // Envio el mensaje.
        Send(Mensaje);
      finally
        Disconnect;
      end;
  //    MessageDlg('Enviado Correctamente', mtInformation, [mbOK], 0);
    except
       // Capturo algunas excepciones que pueden ocurrir
      ON E: EIdProtocolReplyError do begin
      MessageDlg('No se ha podido enviar el email.' + #13 +
            'Incorrecto el email o el usuario o la password.', mtError, [mbOK], 0);
      end;
      on E: EFOpenError do begin
      MessageDlg('No se ha podido enviar el email.' + #13 +
            'Fichero Adjunto desconocido o erróneo.', mtError, [mbOK], 0);
      end;
      on E: EIdSocketError do begin
      MessageDlg('No se ha podido enviar el email.'+ #13 +
            'Host desconocido o incorrecto.', mtError, [mbOK], 0);
      end
      else begin
      MessageDlg('Fallo en el envio de email', mtError, [mbOK], 0);
      end;
    end;
  end;
  ENd;

Última edición por dec fecha: 09-12-2005 a las 12:31:27. Razón: ¡¡Encerrad el código fuente entre las etiquetas [DELPHI] ... [/DELPHI]!!
Responder Con Cita