Content of first part lost when second part present

Giganews Newsgroups
Subject: Content of first part lost when second part present
Posted by:  Frank Jagusch (FJagus…@q-soft.de)
Date: Thu, 27 May 2004

I'm trying to generate mails using TIdSMTP and TIdMessage. I'm working with
Delphi 6 and Indy 9.0.14.
Here's the important part of my (sample) code:
    IdMessage:=TIdMessage.Create(self);
    IdMessage.Recipients.EMailAddresses:='Y…@You.com';
    IdMessage.From.Text:='…@I.com';
    IdMessage.Subject:='Subject of Testmail';
    TIdText.Create(IdMessage.MessageParts);
    TIdText(IdMessage.MessageParts.Items[0]).Body.Text:='Hello World';
//    TIdAttachment.Create(IdMessage.MessageParts,'D:\temp\testfile.txt');
//The testfile.txt contains only a 'Hallo'.
    IdSMTP.Send(IdMessage);

As shown it works fine - I'm getting a multipart mail containing one part:

  From: …@I.com
  Subject: Subject of Testmail
  To: Y…@You.com
  Content-Type: multipart/alternative;
boundary="=_NextPart_2rfkindysadvnqw3nerasdf"
  MIME-Version: 1.0
  Date: Thu, 27 May 2004 12:38:35 +0200
  X-Mailer: SMTP Testclient

  This is a multi-part message in MIME format

  --=_NextPart_2rfkindysadvnqw3nerasdf
  Content-Type: text/plain
  Content-Transfer-Encoding: quoted-printable

  Hello World

  --=_NextPart_2rfkindysadvnqw3nerasdf--

If I uncomment the one line in the code the content of the first part ist
lost:

  From: …@I.com
  Subject: Subject of Testmail
  To: Y…@You.com
  Content-Type: multipart/mixed;
boundary="=_NextPart_2rfkindysadvnqw3nerasdf"
  MIME-Version: 1.0
  Date: Thu, 27 May 2004 12:37:43 +0200
  X-Mailer: SMTP Testclient

  This is a multi-part message in MIME format

  --=_NextPart_2rfkindysadvnqw3nerasdf
  Content-Type: text/plain
  Content-Transfer-Encoding: 7bit

  --=_NextPart_2rfkindysadvnqw3nerasdf
  Content-Type: application/octet-stream;
          name="Neu Textdatei.txt"
  Content-Transfer-Encoding: base64
  Content-Disposition: attachment;
          filename="testfile.txt"

  SGFsbG8=

  --=_NextPart_2rfkindysadvnqw3nerasdf--

While debugging I've seen the content of
TIdText(IdMessage.MessageParts.Items[0]).Body.Text is always present and
unchanged. Even after IdSMTP.Send(IdMessage). But there's nothing in the
mail - so:
What's going wrong? And why? Is there any failure in my usage of TIdMessage?
I assume the change of the Content-Transfer-Enconding of the first part is a
side effect of the loss of the content.

Thanks for reading until here and for your thoughts and answers...

Frank Jagusch

Replies