Rust Requires Chilkat v11.0.0+
Rust
IMAP STARTTLS (Explicit TLS/SSL)
The StartTls property is set to force the Connect method to automatically convert an connection to TLS/SSL via the STARTTLS IMAP command.This is also known as "explicit TLS/SSL" as opposed to "implicit TLS/SSL". With implicit TLS/SSL, the IMAP client connects on the well-known IMAP TLS/SSL port 993 and the secure channel is immediately established. With explicit TLS/SSL, the IMAP client connects on the typical non-secure port (143 usually) and the converts the connection via the STARTTLS command.
Chilkat Rust Downloads
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let imap = chilkat::Imap::new();
// Indicate that STARTTLS should be used to convert
// to a secure TLS/SSL connection:
imap.set_start_tls(true);
imap.set_port(143);
// Connect to an IMAP server and convert the connection
// to TLS/SSL via STARTTLS.
if imap.connect("imap.example.com").is_err() {
println!("{}", imap.last_error_text());
return;
}
// The remainder of this example is the same as for
// non-TLS/SSL...
// Login
if imap.login("myLogin", "myPassword").is_err() {
println!("{}", imap.last_error_text());
return;
}
// Select an IMAP mailbox
if imap.select_mailbox("Inbox").is_err() {
println!("{}", imap.last_error_text());
return;
}
// Get the message IDs of all the emails in the mailbox
let fetch_uids = true;
let message_set = chilkat::MessageSet::new();
if imap.query_mbx("ALL", fetch_uids, &message_set).is_err() {
println!("{}", imap.last_error_text());
return;
}
// Fetch the emails into a bundle object:
let bundle = chilkat::EmailBundle::new();
let headers_only = false;
if imap.fetch_msg_set(headers_only, &message_set, &bundle).is_err() {
println!("{}", imap.last_error_text());
return;
}
// Loop over the bundle and display the FROM and SUBJECT of each.
let email = chilkat::Email::new();
let mut i = 0;
let num_emails = bundle.message_count();
while i < num_emails {
let _ = bundle.email_at(i, &email);
println!("{}", email.from());
println!("{}", email.subject());
println!("--");
i = i + 1;
}
// Disconnect from the IMAP server.
let _ = imap.disconnect().is_ok();