Re: Lose BCC info when save to stream?

Giganews Newsgroups
Subject: Re: Lose BCC info when save to stream?
Posted by:  Remy Lebeau \(Indy Team\) (no.spam@no.spam.com)
Date: Fri, 19 Jan 2007

"Dan" <onsi…@hpassist.com> wrote in message
news:5B9AAAFDBB17E340onsi…@hpassist.com...

> Later, when I want to send the email, I read the stream from the
field,
> then load into a TidMessage from stream.  All of the info is correct
> including attachment, recipients, CCList, except BCCList is empty,
> where it wasn't before I saved it to the stream.  Is this a bug?

It is not a bug.  By design, TIdMessage.SaveToStream() does not
generate the BCC header in the stored message data, so there is
nothing for TIdMessage.LoadFromStream() to restore later.  Only
TIdMessage.SaveToFile() generates the BCC header.  The reason for this
is because
SaveToStream() can be called when sending a message over a socket, so
the BCC header is not allowed to be generated in that situation.

With that said, TIdMessage does have an FGenerateBCCListInHeader
member that controls this behavior.  It is not declared as public, but
it is declared as protected.  So you have use an accessor class to
gain access to it and set it to true before calling SaveToStream(),
ie:

    type
        TIdMessageAccess = class(TIdMessage);

    procedure Tform1.bcctestClick(Sender: TObject);
    var
        zEmailStream: TMemoryStream;
        zNotifyMsg:TIdMessage;
    begin
        zEmailStream := TMemoryStream.Create;
        try
            zNotifyMsg := TIdMessage.Create;
            try
                zNotifyMsg.BccList.EMailAddresses := 'a…@test.com';
                zNotifyMsg.CCList.EMailAddresses := 'e…@test.com';
                TIdMessageAccess(zNotifyMsg).FGenerateBCCListInHeader
:= True; // <-- here
                zNotifyMsg.SaveToStream(zEmailStream);
                zEmailStream.Position := 0;
                zNotifyMsg.Clear;
                zNotifyMsg.LoadFromStream(zEmailStream);
            finally
                zNotifyMsg.Free;
            end;
        finally
            zEmailStream.Free;
        end;
    end;

Gambit

Replies

In response to

Lose BCC info when save to stream? posted by Dan on Fri, 19 Jan 2007