Sample code for 30+ languages & platforms
JavaScript

Upload (Append) Email to an IMAP Mailbox

Upload / append an email to an IMAP mailbox.
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;

// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

var imap = new CkImap();

// Connect to an IMAP server.
// Use TLS
imap.Ssl = true;
imap.Port = 993;
success = imap.Connect("imap.example.com");
if (success !== true) {
    console.log(imap.LastErrorText);
    return;
}

// Login
success = imap.Login("myLogin","myPassword");
if (success !== true) {
    console.log(imap.LastErrorText);
    return;
}

var email = new CkEmail();

// Load the email from a .eml file.
success = email.LoadEml("myEmail.eml");
if (success !== true) {
    console.log(email.LastErrorText);
    return;
}

success = imap.AppendMail("Inbox",email);
if (success !== true) {
    console.log(imap.LastErrorText);
    return;
}

console.log("Email uploaded to Inbox!");

// Disconnect from the IMAP server.
success = imap.Disconnect();