Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Bug with TIdMessageBuilderHtml and TIdAttachmentFile
#1
I run into a real problem here.

I have just found out that when I create an HTML email using TIdMessageBuilderHtml and also want to attach a file using TIdAttachmentFile, the file attachment fails.

It does not make a difference in which order I do it.
Is there anything I can do to fix it?

Code:
with TIdMessageBuilderHtml.Create do
    try
      PlainText.Text := PlainBody;
      Html.Text := HTMLBody;
      FillMessage(IdMessage);
    finally
      Free;
    end;

TIdAttachmentFile.Create(IdMessage.MessageParts, AAttachment);
idMessage.SaveToFile('msg.eml');

When opening the saved file, no attachments. Obviousely also when I actually send it with SMTP.
---
Bart Kindt
CEO and Developer
SARTrack Limited
New Zealand
www.sartrack.nz
Reply
#2
(10-27-2024, 07:08 PM)BartKindt Wrote: I have just found out that when I create an HTML email using TIdMessageBuilderHtml and also want to attach a file using TIdAttachmentFile, the file attachment fails.

Is there a reason why you are not including the attachment in the TIdMessageBuilderHtml to begin with? The email layout is setup according to the content of the builder. If you just blindly add a new attachment after invoking the builder, you might end up creating an invalid email as you potentially break the layout that the builder setup. For instance, the email's ContentType won't be taking the new attachment into account.

(10-27-2024, 07:08 PM)BartKindt Wrote: Is there anything I can do to fix it?

Yes. Use the builder the way it is meant to be used. It has an Attachments property for this exact purpose, eg:

Code:
with TIdMessageBuilderHtml.Create do
try
  PlainText.Text := PlainBody;
  Html.Text := HTMLBody;
  Attachments.Add(AAttachment); // <-- HERE
  FillMessage(IdMessage);
finally
  Free;
end;
idMessage.SaveToFile('msg.eml');

Reply
#3
(10-28-2024, 01:38 AM)rlebeau Wrote: Yes. Use the builder the way it is meant to be used. It has an Attachments property for this exact purpose, eg:

I was not aware of that option. Now it works.

Thanks Remy
---
Bart Kindt
CEO and Developer
SARTrack Limited
New Zealand
www.sartrack.nz
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)