Sample code for 30+ languages & platforms
Rust

Verify Email Recipients

A way to possibly determine valid/invalid email addresses. I would recommend being very careful about doing this because your IP address may be flagged as a potential spammer by the mail server (because you are probing for valid/invalid email addresses). This Chilkat functionality existed for many years, before this kind of activity became a problem. The functionality remains only because it is useful for some to test with their own SMTP servers.

Chilkat Rust Downloads

Rust

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

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

// SMTP connection settings...
mailman.set_smtp_host("smtp.example.com");
mailman.set_smtp_username("MY_SMTP_USERNAME");
mailman.set_smtp_password("MY_SMTP_PASSWORD");
mailman.set_smtp_ssl(true);
mailman.set_smtp_port(465);

// Create a new email object
let email = chilkat::Email::new();

email.set_subject("This is a test");
email.set_body("This is a test");
email.set_from("myemail@example.com");
let _ = email.add_to("person1", "person1@example.com").is_ok();
let _ = email.add_to("person2", "person2@example.com").is_ok();
let _ = email.add_to("person3", "person3@example.com").is_ok();
// The SMTP server smtp.example.com won't know anything about an email address @somewhere_else.com
let _ = email.add_to("person3", "person4@somewhere_else.com").is_ok();
// ...

// Verify recipients.
// **** See the warning about using this API method in the description above.
// (An SMTP server only knows valid email address for its own domain.  For example,
// smtp.example.com *may* only know if person1@example.com is valid or invalid, but does
// not know anything about the validity of email addresses having other domains.)
let bad_addrs = chilkat::StringArray::new();
if mailman.verify_recips(&email, &bad_addrs).is_err() {
    println!("{}", mailman.last_error_text());
    return;
}

let mut i = 0;
while i < bad_addrs.count() {
    println!("{}", bad_addrs.get_string(i).unwrap_or_default());
    i = i + 1;
}

println!("done.");