ParentPart of TIdText throws list index out of bounds

Giganews Newsgroups
Subject: ParentPart of TIdText throws list index out of bounds
Posted by:  Dave Lawnicki (…@here.com)
Date: Fri, 6 Feb 2009

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.

I pulled the components off SVN, compiled and installed properly, but I
cann't send any messages with a ParentPart assigned to anything other
than -1 without receiving a 'List index out of bounds' error. I also get the
same error if I use attachments with the MessageBuilder classes.

Here is a sample of what I tried:

procedure TForm1.Button3Click(Sender: TObject);
var
  oMessage: TIdMessage;
begin
    oMessage := TIdMessage.Create(nil);
    oMessage.ContentType := 'multipart/mixed';

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

      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;

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

      oMessage.From.Address  := '…@here.com
      oMessage.From.Name      := 'Dave';
      oMessage.Recipients.EMailAddresses := '…@here.com';
      oMessage.Subject  := 'Test email';

      SendMail.Connect;

      try
        SendMail.Send(oMessage);
      except on E:Exception do
        ShowMessage('Error sending: ' + E.Message);
      end;
    finally
      oMessage.Free;

      if SendMail.Connected then
        SendMail.Disconnect;
    end;
end;

Replies