Re: TIdAttachmentFile and subject header did not work

Giganews Newsgroups
Subject: Re: TIdAttachmentFile and subject header did not work
Posted by:  Remy Lebeau \(Indy Team\) (re…@lebeausoftware.org)
Date: Mon, 26 Jul 2010

"Alan T" <alan_NO_SPAM_plt…@yahoo.com.au> wrote in message
news:A69FD38DC7B7E340alan_NO_SPAM_plt…@yahoo.com.au...

> Indy 10, D2007
> I tried to attach files but the file is embedded as text in the email
> body and also my email did not show up the subject in my OutLook.

That is because you are assigning the wrong value to the
TIdMessage.ContentType property.  You need to set it to "multipart/mixed"
instead of "text/plain", ie:

emailMessage.ContentType := 'multipart/mixed';

With that said, consider using the TIdMessageBuilderPlain class instead.  It
will ensure the TIdMessage is set up properly, ie:

emailMessage := TIdMessage.Create;
try
  with TIdMessageBuilderPlain.Create do
  try
    PlainText.Text := fEmailMessageList.Text;
    Attachments.Add('C:\Temp\ClientReportService\reports\Sales(AllMarket)_Nat_All_All_Week_20100719.pdf');
    FillMessage(emailMessage);
  finally
    Free;
  end;
  emailMessage.Subject := 'This is a dummy email';
  emailMessage.Headers.Add(fEmailTitle);
  emailMessage.Sender.Address := fSenderEmail;
  emailMessage.From.Text := fSenderEmail;
  emailMessage.ReplyTo.EMailAddresses := fReplyToEmail;
  ...
finally
  emailMessage.Free;
end;

--
Remy Lebeau (Indy Team)

Replies

None

In response to

TIdAttachmentFile and subject header did not work posted by Alan T on Fri, 23 Jul 2010