Ver Mensaje Individual
  #6  
Antiguo 08-11-2007
Avatar de ArdiIIa
[ArdiIIa] ArdiIIa is offline
Miembro Premium
 
Registrado: nov 2003
Ubicación: Valencia city
Posts: 1.481
Reputación: 22
ArdiIIa Va por buen camino
Ok.
Te pongo unas porciones de código que utilizo para enviar emails mediante un Thread en Backgorund.

La idea es extraer las imágenes de la BD a un directorio temporal y seguidamente procesarlas para incluirlas en el cuerpo del mensaje.

Como te digo, son partes de código que seguramente te sea de ayuda, el resultado final, dependerá de tu pericia.

Código Delphi [-]

constructor TSendMail.Create(TmpDir: String);
begin
  inherited Create(True);
  FTempDir := TmpDir;
  Priority := tpIdle;
  FreeOnTerminate := True;
  FTmpStream := TMemoryStream.Create;
  IdSMTP := TIdSMTP.Create(nil);
  IdMessage := TIdMessage.Create(NIL);
  p :=  IdMessage.MessageParts;
  slBody := TstringList.Create;

    slBody.Add('');
    slBody.Add('');
    slBody.Add('');
    slBody.Add('');

     if findFirst(FTempDir + '*.jpg',faAnyFile ,sr) = 0 THEN
        REPEAT
        OpenfileJPG :=  FTempDir + SR.Name;
        slBody.Add('');
        idAttach := TidAttachment.Create(p, OpenfileJPG);
        idAttach.ContentType := 'image/jpeg';
        idAttach.ContentDisposition := 'inline';
        idAttach.ExtraHeaders.Values['content-id'] := Sr.Name;
        idAttach.DisplayName := Sr.Name;
        until FindNext(sr) <> 0;
        FindClose(sr);
    slBody.Add('');
    slBody.Add('');
FormMain.ProgressBar.Position := 0;
FormMain.ProgressBar.Visible := True;
end;


procedure TSendMail.Execute;
Var cTemp : String;
begin
  try
    while GlobalFindAtom('SEND_MAIL_BACK')  <> 0 do
    BEGIN
    SLEEP(1000);
    END;

    GlobalAddAtom('SEND_MAIL_BACK');
    Cuentas := TAccountItems.Create;
    LoadOptions(Cuentas);
    cTemp := '@' + copy(Cuentas[Cuentas.Principal].ServerPop3,1 + Pos('.', Cuentas[Cuentas.Principal].ServerPop3),99);
    IdMessage.From.Address := Cuentas[Cuentas.Principal].Login + cTemp;
    IdMessage.From.Name := Cuentas[Cuentas.Principal].Name;
    IdMessage.Recipients.Add;
    IdMessage.ContentType := 'multipart/mixed';
    IdSMTP.Username  := Cuentas[Cuentas.Principal].Login;
    IdSMTP.Host      := Cuentas[Cuentas.Principal].ServerSMTP;
    IdSMTP.Password  := Cuentas[Cuentas.Principal].Password;
    idText1 := TidText.Create(p, slBody);
    idText1.ContentType := 'text/html';
    idText2 := TidText.Create(p);
    idText2.ContentType := 'text/plain';
    idText2.Body.Add('UTILICE EL MODO APAISADO DE IMPRESIÓN SI DESEA IMPRIMIR EL DOCUMENTO, ');
    IdMessage.Body.Assign(slBody);
    IdMessage.SaveToStream(FTmpStream,False);
    FormMain.ProgressBar.Max := FTmpStream.Size;
    FormMain.ProgressBar.Position := 0;
    FormMain.ProgressBar.Visible := True;
    IdSMTP.OnWork := IdSMTPWork;
    IdSMTP.OnStatus := IdSMTPStatus;
    IdSMTP.AuthenticationType := atNone;
    IdSMTP.Connect;
    if IdSMTP.AuthSchemesSupported.IndexOf('LOGIN')>-1 then
    begin
      IdSMTP.AuthenticationType := atLogin;
      IdSMTP.Authenticate;
    end;
    idSMTP.Send(idMessage);

    Synchronize(Sound);
    FStatus := 'MAIL ENVIADO CORRECTAMENTE';
    Synchronize(UpdateStatus);
     //Borrado de ficheros y directorio temporal
    if findFirst(FTempDir + '*.*',faAnyFile ,sr) = 0 THEN
     REPEAT
     DeleteFile(FTempDir + SR.Name);
     until FindNext(sr) <> 0;
     FindClose(sr);
     RemoveDir(FTempDir);

   finally
   FStatus := 'ERROR INDETERMINADO';
   Synchronize(UpdateStatus);
   CleanUP;
   end;
end;
__________________
Un poco de tu generosidad puede salvar la vida a un niño. ASÍ DE SENCILLO
Responder Con Cita