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

August 7, 2007

Adding a .mht File to an Email as a File Attachment

The Chilkat Email object’s AddFileAttachment method accepts a single string argument: the filepath of the file to be loaded into memory and attached to the email. The Content-Type of the attachment sub-part (in the email MIME) is automatically determined by the file extension. For example, if you attach a .jpg, the content type is "image/jpeg". The content-type string is returned by AddFileAttachment (for the benefit of any application that needs to know).

The tricky thing about MHT files is that the content-type for ".mht" is "message/rfc822″. Email clients such as Outlook, Mozilla Thunderbird, GMail, etc. will treat attachments differently depending on the content-type. For example, some email clients may automatically inline image or text attachments. An email client may also try to inline "message/rfc822″ attachments, and this may not be what you want if you simply want the .mht to be treated as an file attachment and not inlined.

The solution is to instead call AddFileAttachment2( filename, contentType ), where you may explicitly set the content-type. Any unrecognized file extension automatically maps to the content-type "application/octet-stream", which is a good choice if you don’t want the attachment inlined:

(in C#)
bool success = emailObject.AddFileAttachment2("test.mht","application/octet-stream");


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

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