Rust Requires Chilkat v11.0.0+
Rust
Delete Individual Emails from POP3 Mailbox
Demonstrates how to delete individual emails from a POP3 mailbox.Chilkat Rust Downloads
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
// The mailman object is used for receiving (POP3)
// and sending (SMTP) email.
let mailman = chilkat::MailMan::new();
// Set the POP3 server's hostname
mailman.set_mail_host("pop.example.com");
// Set the POP3 login/password.
mailman.set_pop_username("myLogin");
mailman.set_pop_password("myPassword");
// Set the ImmediateDelete property = false
// When the DeleteEmail method is called, the POP3 session
// will remain open and the emails will be deleted all at once
// when the session closes.
mailman.set_immediate_delete(false);
// Download email headers.
let bundle = chilkat::EmailBundle::new();
let keep_on_server = true;
let headers_only = true;
let num_body_lines = 1;
if mailman.fetch_all(keep_on_server, headers_only, num_body_lines, &bundle).is_err() {
println!("{}", mailman.last_error_text());
return;
}
let email = chilkat::Email::new();
let mut i = 0;
while i < bundle.message_count() {
let _ = bundle.email_at(i, &email);
println!("From: {}", email.from());
println!("Subject: {}", email.subject());
// If you decide the email is to be deleted, call DeleteEmail.
// This marks the email for deletion on the POP3 server.
if mailman.delete_email(&email).is_err() {
println!("{}", mailman.last_error_text());
return;
}
i = i + 1;
}
// Make sure the POP3 session is ended to finalize the deletes.
if mailman.pop3_end_session().is_err() {
println!("{}", mailman.last_error_text());
return;
}
println!("Success!");