Sample code for 30+ languages & platforms
Rust

Explicitly Begin a POP3 Session

See more POP3 Examples

Demonstrates the Chilkat MailMan.Pop3BeginSession method, which explicitly begins a POP3 session by connecting to the POP3 server and authenticating using the current POP3 property settings. Calling it is optional. This example begins a session, performs a mailbox operation, and ends the session.

Background: Pop3BeginSession combines connecting and authenticating into one call. Chilkat does this automatically when a mailbox operation needs it, so the value of calling it explicitly is control: you open one session, perform several operations against it, and close it with Pop3EndSession — avoiding repeated connect/authenticate round trips and keeping deletion marks within a single, well-defined session.

Chilkat Rust Downloads

Rust

// Demonstrates the MailMan.Pop3BeginSession method, which explicitly begins a POP3 session
// by connecting to the POP3 server and authenticating using the current POP3 property
// settings.

let mailman = chilkat::MailMan::new();

// Configure the POP3 server connection.
mailman.set_mail_host("pop.example.com");
mailman.set_mail_port(995);
mailman.set_pop_ssl(true);
mailman.set_pop_username("user@example.com");
mailman.set_pop_password("myPassword");

// Explicitly begin the POP3 session (connect + authenticate).

if mailman.pop3_begin_session().is_err() {
    println!("{}", mailman.last_error_text());
    return;
}

// Perform one or more mailbox operations within this single session.
println!("Mailbox count: {}", mailman.get_mailbox_count());

// End the session when finished.
if mailman.pop3_end_session().is_err() {
    println!("{}", mailman.last_error_text());
    return;
}

println!("POP3 session completed.");