Sample code for 30+ languages & platforms
Rust

Upload .eml File to an IMAP Mailbox

See more IMAP Examples

Demonstrates how to upload the MIME source of an email to a mailbox on an IMAP server.

Chilkat Rust Downloads

Rust

let imap = chilkat::Imap::new();

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

// Connect to an IMAP server.
// Use TLS
imap.set_ssl(true);
imap.set_port(993);
if imap.connect("MY-IMAP-DOMAIN").is_err() {
    println!("{}", imap.last_error_text());
    return;
}

// Login
if imap.login("MY-IMAP-LOGIN", "MY-IMAP-PASSWORD").is_err() {
    println!("{}", imap.last_error_text());
    return;
}

let sb_mime = chilkat::StringBuilder::new();
let _ = sb_mime.load_file("qa_data/eml/emoji_pizza.eml", "utf-8");

// Upload to the mailbox.
if imap.append_mime("[Gmail]/testFolder", &sb_mime.get_as_string().unwrap_or_default()).is_err() {
    println!("{}", imap.last_error_text());
    return;
}

let _ = imap.disconnect();

println!("OK.");