Re: attache stream

Giganews Newsgroups
Subject: Re: attache stream
Posted by:  Remy Lebeau \(TeamB\) (no.spam@no.spam.com)
Date: Sat, 27 Sep 2008

"Gilberto Cardoso" <gilber…@mgr.com.br> wrote in message
news:CFFF9883A664E340gilber…@mgr.com.br...

> I'm using Indy10 smtp to send emails with attachemet.
> Can I attache stream (file) stored in DB?

Yes.  You have two choices:

1) use TIdAttachmentMemory.  You can copy the DB data into it using its
PrepareTempStream() and FinishTempStream() methods:

    var
        Stream: TStream;
    begin
        with TIdAttachmentMemory.Create(IdMessage1.MessageParts) do
        begin
            Stream := PrepareTempStream;
            // write data into Stream as needed...
            FinishTempStream;
        end;
    end;

2) derive a new class from TIdAttachment and override its OpenLoadStream()
method to return a TStream that directly reads from the DB:

    type
        TIdAttachmentDB = class(TIdAttachment)
        protected
            FDataStream: TStream;
        public
            function OpenLoadStream: TStream; override;
            procedure CloseLoadStream; override;
        end;

    function TIdAttachmentDB.OpenLoadStream: TStream;
    begin
        FDataStream := SomeTStreamObject; // such as via
TDataSet.CreateBlobStream()
        Result := FDataStream;
    end;

    procedure TIdAttachmentDB.CloseLoadStream;
    begin
        FreeAndNil(FDataStream);
    end;

--
Remy Lebeau (TeamB)

Replies

None

In response to

attache stream posted by Gilberto Cardoso on Fri, 26 Sep 2008