Lost with HTML mail + pdf attachment

Giganews Newsgroups
Subject: Lost with HTML mail + pdf attachment
Posted by:  Gerard Visent (gera…@zootec.ad)
Date: Thu, 05 May 2005

Hi all.

I have an app that is supposed to send HTML mails to customers + a pdf
and in some cases a text file.
I don't know how to assign the file's attachments ParentPart property so
they show up correctly in all the mail clients.

This is my code:

  idMessage.ContentType := 'multipart/mixed';

  idMultipartAlternative := TIdText.Create(idMessage.MessageParts, nil);
  with idMultipartAlternative do
  begin
      ContentType := 'multipart/alternative';
  end;

  // Text body    
  idTextPlain := TIdText.Create(idMessage.MessageParts, nil);
  with idTextPlain do
  begin
      ParentPart := 0;
      ContentType := 'text/plain';
      Body.Text := BodyText;
  end;

  idMultipartRelated := TIdText.Create(idMessage.MessageParts, nil);
  with idMultipartRelated do
  begin
      ContentType := 'multipart/related';
  end;

  // HTML Body
  idTextHtml := TIdText.Create(idMessage.MessageParts, nil);
  with idTextHtml do
  begin
      ParentPart := idMultipartRelated.Index;
      ContentType := 'text/html';
      Body.Text := BodyHTML;
  end;

  // Images in HTML
  for i := 0 to AttachmentsHTML.Count-1 do
  begin
    with TIdAttachmentFile.Create(idMessage.MessageParts,
AttachmentsHTML[i]) do
    begin
        ParentPart := idMultipartRelated.Index;
        ContentID := AttachmentsHTML[i];
        ContentType := GetMIMETypeFromFile(AttachmentsHTML[i]);
    end;
  end;

  // Other attachments (PDF, TXT)
  for i := 0 to AttachmentsAltres.Count-1 do
  begin
    with TIdAttachmentFile.Create(idMessage.MessageParts,
AttachmentsAltres[i]) do
    begin
        ParentPart :=  idMultipartAlternative.Index; //-1
        ContentID := AttachmentsAltres[i];
        ContentType := GetMIMETypeFromFile(AttachmentsAltres[i]);
    end;
  end;

This is where I have problems.
With ParentPart := -1, my inicial try, the attachments show correctly in
Outlook express 6 and Mozilla 1.7, but not in Outlook 2000.
with ParentPart := idMultipartAlternative.Index it's a little bit
better, I can get the attachments from the message in Outlook 2000, but
in the general message view there is clip icon showing the message has
an attachment.

Does anybody have an idea on how to do this and get results with all
mail clients?

TIA,

Gerard.

Replies