Rust
Rust
SMTP Send Raw Command
Demonstrates how to send a raw command to the SMTP server after the connecting and authenticating.Chilkat Rust Downloads
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let mailman = chilkat::MailMan::new();
mailman.set_smtp_host("smtp.mail.us-west-2.awsapps.com");
mailman.set_smtp_ssl(true);
mailman.set_smtp_port(465);
if mailman.smtp_connect().is_err() {
println!("{}", mailman.last_error_text());
return;
}
mailman.set_smtp_username("john@example.com");
mailman.set_smtp_password("the_password");
if mailman.smtp_authenticate().is_err() {
println!("{}", mailman.last_error_text());
return;
}
println!("Authenticated!");
// Send the "EHLO" command again to get the multi-line response that includes the SMTP capabilities.
// The capabilities are the lines in the response that begin with "250-".
let Ok(response_str) = mailman.smtp_send_raw_command("EHLO client.example.com", "utf-8", false) else {
println!("{}", mailman.last_error_text());
return;
};
println!("{}", response_str);
// A sample response:
// 250-smtp.us-west-2.mail.awsapps.com
// 250-8BITMIME
// 250-AUTH PLAIN LOGIN
// 250 Ok