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

Forward an email as an attachment

See more Email Object Examples

Attach the original Email to a new message as a message/rfc822 part. The recipient can open the attached email and read its original headers and body.

Chilkat Node.js Downloads

Node.js
NODEJS_PRELUDE

function chilkatExample() {

    var success = false;

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

    var original = new chilkat.Email();
    success = original.LoadEml("message.eml");
    if (success !== true) {
        console.log(original.LastErrorText);
        return;
    }

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

    email.Subject = "Forwarded message";
    email.Body = "The original email is attached.";
    success = email.AttachEmail(original);
    if (success !== true) {
        console.log(email.LastErrorText);
        return;
    }

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

    console.log("Saved forward-as-attachment.eml.");

}

chilkatExample();