HTML with attachments

Giganews Newsgroups
Subject: HTML with attachments
Posted by:  Paulo Tesche (pstesc…@hotmail.com)
Date: Sun, 17 Aug 2003

Hi folks,

I´m almost done with my BCB6 e-mail sender application but I have one last problem.
I´m sure it´s something I missed in the examples of Indy(they are mainly in Delphi).
The Indy version I´m usig is 9.00.14
I can successfully send messages with plain text or HTML formatted too. But when it cames to include attachments it works only with plain text messages.
If a HTML formatted message with attachment(s) is sent, the message is sent OK but arrives with the HTML code shown as plain text.
I´m using Outlook 2000 and Outlook Express as mail readers.
What is wrong with my code?
The piece of code that sends the message is listed above...

void __fastcall TFrmMain::btSendClick(TObject *Sender)
{
  IdSMTP1->Connect ();

  // Msg is a TIdMessage component
  Msg->ClearBody ();
  Msg->ClearHeader ();

  Msg->From->Text = ebFromEmail->Text;
  Msg->From->Name = ebFromName->Text;
  Msg->Recipients->EMailAddresses = ebTo->text;
  Msg->Subject = ebSubject->Text;
  Msg->ReplyTo->EMailAddresses = ebReturnTo->Text;

  Msg->Body->LoadFromFile (dlgHTML->FileName);
  Msg->ContentType = "text/html";

  // Adds the attachments
  int i;
  for (i=0; i<grdAttach->RowCount-1; i++)
  {
    Msg->MessageParts->Add();
    new TIdAttachment(Msg->MessageParts, grdAttach->Cells[1][i]);
  }

  try
  {
    IdSMTP1->Send (Msg);
  }

  catch (...)
  {
  }

  IdSMTP1->Disconnect ();
}

Replies