Re: MessageParts.Clear

Giganews Newsgroups
Subject: Re: MessageParts.Clear
Posted by:  Remy Lebeau \(Indy Team\) (no.spam@no.spam.com)
Date: Tue, 24 Mar 2009

"Richard Hayward" <richa…@tortoise.demon.co.uk> wrote in message
news:3b6hs49oe2fo6e1ip4g11u7dh9njqu3k…@4ax.com...

> I'm using D6 with Indy 8.0.25.

That is a VERY old version of Indy that is no longer supported.

> I have a message, to which an attachment has been added, using
>
> TIdAttachment.Create(IdMessage.MessageParts, OpenDialog.FileName);
>
> I then want to remove this, and any other attachments,
> using
>
> IdMessage.MessageParts.Clear;

That will clear out ALL message parts, text and attachments alike.  If you
just want to remove the attachments, you have to remove them individually,
ie:

I := 0;
while I < IdMessage.MessageParts.Count do
begin
    if IdMessage.MessageParts[I] is TIdAttachment then
        IdMessage.MessageParts[I].Free
    else
        Inc(I);
end;

> but when I send this message, supposedly without attachments, the
> raw message looks something like this:

Clearing out items from the MessageParts collection does not change any
existing values in the TIdMessage.Headers or TIdMessage.Body properties.
You have to do that separately, ie:

IdMessage.ContentType := 'text/plain';

> Is MessageParts.clear not alone sufficient to remove attachments?

No, it is not.

--
Remy Lebeau (TeamB)

Replies

In response to

MessageParts.Clear posted by Richard Hayward on Tue, 24 Mar 2009