Zip Component, Email Component, Encryption Component ActiveX Control for Zip Compression .NET Components for ASP.NET
ActiveX and .NET Components for Zip Compression, Encryption, Email, XML, S/MIME, HTML Email, Character Encoding, Digital Certificates, FTP, and more ASP Email ActiveX Component

Index of Chilkat Blog Posts

February 13, 2006

Adding .MHT files as Email Attachments


I use the method AddFileAttachment to add attachments to a CkEmail object.
When the attachment is an mht file, I encountered the next problems:
- the return value is TRUE,
- the method get_NumAttachments() returns 0 (?).
- the method SetAttachmentFilename() returns FALSE. I receive the next error message:
Index out of range: no attachment at index = 0.
index: 0
num_attachments: 0
- the attachment sent has no name (because the SetAttachmentFilename failed),
- the attachment sent is empty.


Chilkat treats attached messages differently than file attachments. The .mht file extension defaults to a content-type of message/rfc822, so when a .mht file is added, it will appear as an attached message. (You can use the methods/properties dealing with attached messages.)

An alternative is to call AddFileAttachment2 where you can directly specify the content-type:


The "application/octet-stream" is the content type that is used for any unrecognized file extension (.dat for example). This will cause Chilkat to behave correctly, and email clients such as Outlook, Thunderbird, etc. should also treat it as a normal file attachment (i.e. it shouldn’t inline the attachment into your email.)

Privacy Statement. Copyright 2000-2011 Chilkat Software, Inc. All rights reserved.
Send feedback to

Components for Microsoft Windows XP, 2000, 2003 Server, Vista, Windows 7, and Windows 95/98/NT4.