Sample code for 30+ languages & platforms
Node.js Requires Chilkat v11.0.0+

Set a MIME header on one attachment

See more Email Object Examples

Add a file using the content type required by the receiving application. Set Content-Description on the newly added MIME part and read it back from that part. The message-level headers have a separate collection.

Chilkat Node.js Downloads

Node.js
NODEJS_PRELUDE

function chilkatExample() {

    var success = false;

    //  Assumes Chilkat is unlocked. See Global Unlock Sample.

    var email = new chilkat.Email();
    email.From = "Workshop team <events@example.com>";
    success = email.AddTo("Alex Rivera","alex@example.net");
    if (success !== true) {
        console.log(email.LastErrorText);
        return;
    }

    email.Subject = "Workshop registration";
    email.Body = "Attached is the requested data file.";
    success = email.AddFileAttachment2("sample.hpm","application/x-hprimnet");
    if (success !== true) {
        console.log(email.LastErrorText);
        return;
    }

    var index = email.NumAttachments - 1;
    email.AddAttachmentHeader(index,"Content-Description","HPM/3.0");
    console.log(email.GetAttachmentHeader(index,"Content-Description"));

    success = email.SaveEml("described-attachment.eml");
    if (success !== true) {
        console.log(email.LastErrorText);
        return;
    }

    console.log("Saved described-attachment.eml.");

}

chilkatExample();