Please verify that this is the correct method to define a multipart/alternate sm

Giganews Newsgroups
Subject: Please verify that this is the correct method to define a multipart/alternate sm
Posted by:  orlando (seasidebru…@hotmail.com)
Date: Mon, 21 Mar 2005

Using release version of Indy 10.0.52

I have noticed that if I do not explicitly define the multipart/related
multpart/alternative content type, I do not properly get the email
correctly.  I would get the text and html parts at once or just the text
part only.  This seems to work for all.

Please provide verification or any suggestions.  Thanks!

============= Here is a sample code:
procedure TForm1.Button2Click(Sender: TObject);
var
  lMessage: TIdMessage;
  lTextPart: TIdText;
  lImagePart: TIdAttachmentFile;
begin
  lMessage := TIdMessage.Create(Self);
  try
    lMessage.From.Address := edFrom.Text;
    lMessage.Subject := 'My test email';
    lMessage.Recipients.Add.Address := edTo.Text;
    lMessage.Body.Clear;
    // declaring that it will be multipart/related with multi-part
alternative block
    lMessage.ContentType := 'multipart/related;
type="multipart/alternative"';

    // define multi-part alternative block
    lTextPart := TIdText.Create(lMessage.MessageParts);
    lTextPart.ContentType := 'multipart/alternative';
    // incrementing the default from -1 to 0 to define as part of the inner
boundary
    lTextPart.ParentPart := 0;

    // ParentPart := 0 sets to be part of the multipart/alternative block
(so will be at the inner boundary)
    lTextPart := TIdText.Create(lMessage.MessageParts);
    lTextPart.Body.Text := 'This is a plain text message';
    lTextPart.ContentType := 'text/plain';
    lTextPart.ParentPart := 0;

    // ParentPart := 0 sets to be part of the multipart/alternative block
(so will be at the inner boundary)
    lTextPart := TIdText.Create(lMessage.MessageParts);
    lTextPart.Body.Text := '<html><body><b>This is a HTML message with
picture</b><img src="cid:amy_graphic_1.jpg" ></body></html>';
    lTextPart.ContentType := 'text/html';
    lTextPart.ParentPart := 0;

    // ParentPart is -1 by default so will be part of the top most boundary
    lImagePart := TIdAttachmentFile.Create(lMessage.MessageParts,
'c:\amy_graphic_1.jpg');
    lImagePart.ContentType := 'image/jpg';
    lImagePart.Headers.Add('Content-ID: <amy_graphic_1.jpg>');
    lImagePart.ParentPart := -1;

    IdSMTP1.Connect;
    try
      IdSMTP1.Send(lMessage);
    finally
      IdSMTP1.Disconnect;
    end;
  finally
    lMessage.Free;
  end;
end;

============= Here is the smtp generated:
X-Message-Status: n
X-SID-PRA: <snip> <<snip>>
X-SID-Result: TempError
X-Message-Info: 6sSXyD95QpWSzLiiNWP10X2qItQoqAekmlJyhXPYv7M=
Received: from <snip> ([<snip>]) by mc4-f27.hotmail.com with Microsoft
SMTPSVC(6.0.3790.211);
  Mon, 21 Mar 2005 18:38:33 -0800
Received: from <snip> [<snip>]
by <snip>
with XWall v3.31g ;
Mon, 21 Mar 2005 18:37:44 -0800
From: "<snip>" <<snip>>
Subject: My test email
To: <snip>
Content-Type: multipart/related; type="multipart/alternative";
boundary="LGH45Acs9hplDBTw1Xh=_LTjQ1j10pkfTn"
MIME-Version: 1.0
Date: Mon, 21 Mar 2005 18:38:31 -0800
Return-Path: <snip>
Message-ID: <<snip>>
X-OriginalArrivalTime: 22 Mar 2005 02:38:33.0643 (UTC)
FILETIME=[3DC137B0:01C52E88]

This is a multi-part message in MIME format

--LGH45Acs9hplDBTw1Xh=_LTjQ1j10pkfTn
Content-Type: multipart/alternative;
        boundary="LGH45Acs9hplDBTw1Xh=_LTjQ1j10pkfTnG"

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

This is a plain text message

--LGH45Acs9hplDBTw1Xh=_LTjQ1j10pkfTnG
Content-Type: text/html
Content-Transfer-Encoding: quoted-printable

<html><body><b>This is a HTML message with picture</b><img src=3D"cid:=
amy_graphic_1.jpg" ></body></html>

--LGH45Acs9hplDBTw1Xh=_LTjQ1j10pkfTnG--

--LGH45Acs9hplDBTw1Xh=_LTjQ1j10pkfTn
Content-Type: image/jpg;
        name="amy_graphic_1.jpg"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
        filename="amy_graphic_1.jpg"
Content-ID: <amy_graphic_1.jpg>

<snip of the encoded jpg image>
--LGH45Acs9hplDBTw1Xh=_LTjQ1j10pkfTn--

Replies