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

Create an HTML reply with a quoted original

See more Email Object Examples

Use ToReply to create a separate message with reply addressing and threading headers. Quote the original as escaped text inside HTML so markup from the incoming message cannot change the reply layout. Save the draft and inspect the recipient before sending.

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.
JavaScript
var success = false;

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

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

var reply = new CkEmail();
success = original.ToReply(reply);
if (success !== true) {
    console.log(original.LastErrorText);
    return;
}

reply.From = "Alex Rivera <alex@example.net>";
reply.RemoveAttachedMessages();
var quote = new CkStringBuilder();
if (original.HasPlainTextBody() == true) {
    quote.Append(original.GetPlainTextBody());
}
else {
    var reader = new CkHtmlToText();
    quote.Append(reader.ToText(original.GetHtmlBody()));
}

var plain = new CkStringBuilder();
plain.AppendLine("Thank you. I will attend.",true);
plain.Append(quote.GetAsString());
success = reply.AddPlainTextAlternativeBody(plain.GetAsString());
if (success !== true) {
    console.log(reply.LastErrorText);
    return;
}

var changed = quote.Replace("&","&amp;");
changed = quote.Replace("<","&lt;");
changed = quote.Replace(">","&gt;");
quote.Prepend("<p>Thank you. I will attend.</p><blockquote><pre>");
quote.Append("</pre></blockquote>");
success = reply.AddHtmlAlternativeBody(quote.GetAsString());
if (success !== true) {
    console.log(reply.LastErrorText);
    return;
}

success = reply.SaveEml("reply.eml");
if (success !== true) {
    console.log(reply.LastErrorText);
    return;
}

console.log("Saved reply.eml.");