Ver Mensaje Individual
  #4  
Antiguo 11-02-2011
elguille elguille is offline
Miembro
 
Registrado: ene 2005
Posts: 114
Reputación: 20
elguille Va por buen camino
Esto seguro que funciona
Código Delphi [-]
procedure email2(host:string;nombre:string;password:string;port:integer;desde:string;hasta:string;asunto:strin  g;cuerpo:string;adjunto:string);
var
    IDSMTP1: TIDSMTP;  // Componente de envio de correo
    mensaje: TIdMessage;
begin
screen.cursor:=crhourglass;
IDSMTP1:=TIDSMTP.Create(nil);
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 := '';
if adjunto<>'' THEN
  TIdAttachmentfile.Create(Mensaje.MessageParts,adjunto);
end;
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: EProtocolReplyError 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;
IDSMTP1.free;
mensaje.free;
screen.cursor:=crdefault;
ENd;
Responder Con Cita