Question:
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:
SetAttachmentFilename:
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.
Answer:
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:
email.AddFileAttachment2("google.mht","application/octet-stream");
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.)