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

Create, save, and reopen a plain-text email

See more Email Object Examples

Set the sender, recipient, subject, and plain-text body. Save the result as an EML file, then open it in a second Email object and read its contents.

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 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 = "Hello";
email.Body = "This is a plain-text message.";
success = email.SaveEml("message.eml");
if (success !== true) {
    console.log(email.LastErrorText);
    return;
}

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

console.log(received.From);
console.log(received.Subject);
console.log(received.GetPlainTextBody());