login about faq

If I send a mail through Chilkat SMTP (ActiveX) and the first attachment is an HTML file, the file will contain the body of the e-mail instead of the actual attached HTML file.

The body of the e-mail itself will be empty as well.

If I put another type of file (like a PDF) first, the HTML files that follow will be correct and the body will be correct as well.

See pictures below:

This is when the HTML attachment is first in the list:

Bad

This is when the HTML is second or later in the list:

Good

UPDATE: The body of the mail will replace the first HTML attachment...

So for example, if the body contains the text 'aaaaa', the HTML attachment (if it's the first attachment in the list) will only contain 'aaaaa' instead of the actual attached HTML.

asked Oct 18 at 05:09

truyb's gravatar image

truyb
32

edited Oct 20 at 04:22


Setting the HTML body of the email first, and then adding attachments (such as an HTML file attachment) should solve this problem.

The issue occurs when you have an empty/new email object, and the very first thing you do is call email.AddFileAttachment to add a file that happens to be an HTML file.

It's somewhat of a sticky situation because Chilkat is handling the auto-formatting of the MIME structure (i.e. multipart/mixed, multipart/related, multipart/alternative) and re-arranging things automatically as parts are added via different method calls -- such as adding a related item, adding a plain-text body after an HTML body is already present, adding attachments, etc.

An email that has file attachments is typically multipart/mixed. But there is the case where an email has no actual body, and just one file attachment. In that case, the email should NOT be multipart/mixed, but should just be the simple non-multipart MIME containing the file attachment. This is what happens when an HTML file attachment is added first. You get an email with MIME that is non-multipart, and the top-level Content-Type is text/html -- basically indistinguishable from an email where SetHtmlBody was first called. Then.. if you call SetHtmlBody, the software replaces the HTML body.

But if you reverse the calls, the semantics of AddFileAttachment are to convert the email to multipart/mixed if a body already exists, and then add the file attachment under the multipart/mixed umbrella. This is why calling SetHtmlBody first, and then calling AddFileAttachment works, but the reverse does not.

link

answered Oct 20 at 17:11

chilkat's gravatar image

chilkat ♦♦
12.8k317366477

That worked. Thank you very much.

(Oct 23 at 02:45) truyb
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×110
×89
×29

Asked: Oct 18 at 05:09

Seen: 190 times

Last updated: Oct 23 at 02:45

powered by OSQA