Re: MessageParts.Clear

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

"Richard Hayward" <richa…> wrote in message

> 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,

I := 0;
while I < IdMessage.MessageParts.Count do
    if IdMessage.MessageParts[I] is TIdAttachment then

> 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)


In response to

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