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:


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


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 '17 at 05:09

truyb's gravatar image


edited Oct 20 '17 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.


answered Oct 20 '17 at 17:11

chilkat's gravatar image

chilkat ♦♦

That worked. Thank you very much.

(Oct 23 '17 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



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



Asked: Oct 18 '17 at 05:09

Seen: 2,969 times

Last updated: Oct 23 '17 at 02:45

powered by OSQA