JavaScript Requires Chilkat v11.0.0+
JavaScript
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.
Note
This example is intended for running within a Chilkat.Js embedded JavaScript engine. All Chilkat JavaScript examples require Chilkat
v11.4.0 or greater.
var success = false;
// Assumes Chilkat is unlocked. See Global Unlock Sample.
var original = new CkEmail();
success = original.LoadEml("message.eml");
if (success !== true) {
console.log(original.LastErrorText);
return;
}
var email = new CkEmail();
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.");