Re: ParentPart of TIdText throws list index out of bounds

Giganews Newsgroups
Subject: Re: ParentPart of TIdText throws list index out of bounds
Posted by:  Remy Lebeau \(Indy Team\) (no.spam@no.spam.com)
Date: Fri, 6 Feb 2009

"Dave Lawnicki" <…@here.com> wrote in message
news:28DE64653475E340…@here.com...

> I was having some problems in the Indy components that were
> shipped with D2009. I need to send an html message with inline
> images, and also have standard attachments.

You are mis-using the ParentPart property.

I strongly suggest using the TIdMessageBuilderHtml class instead of filling
in the TIdMessage manually, so that everything is set up properly.

> I also get the same error if I use attachments with the
> MessageBuilder classes.

I have never seen this problem with them.

> I pulled the components off SVN

Did you download the Trunk or the Tiburon branch?

>      with TIdText.Create(oMessage.MessageParts, nil) do begin
>        ContentType := 'multipart/related';
>        ParentPart := 0;
>      end;

The ParentPart of the first item must be -1, not 0.  You are telling that
part that it is its own parent, which is wrong.

>      with TIdText.Create(oMessage.MessageParts, nil) do begin
>        Body.Text := '<strong>HTML goes here</strong><img
> src="cid:image1.jpg" />';
>        ContentType := 'text/html';
>        ParentPart := 0;
>      end;

That one is correct, as it is to be nested as a child underneath the
'multipart/related' message part.

>      with TIdAttachmentFile.Create(oMessage.MessageParts, 'c:\dev\indy
> mail\logo.jpg') do begin
>        ContentID := '12345';
>        ContentType := 'image/jpeg';
>        FileName := 'image1.jpg';
>        ParentPart := -1;
>      end;

You are telling the attachment that it has no parent, which is wrong.  It
should be set to 0 as well, not -1, as it is also to be nested as a child
underneath the 'multipart/related' message part.

--
Remy Lebeau (TeamB)

Replies

None

In response to

ParentPart of TIdText throws list index out of bounds posted by Dave Lawnicki on Fri, 6 Feb 2009