Rust
Rust
Send an SMTP NOOP Command
See more SMTP Examples
Demonstrates the Chilkat MailMan.SmtpNoop method, which sends an SMTP NOOP command to the server. NOOP does nothing except elicit a positive response, which is useful for keeping a connection alive or verifying it is still responsive. This example opens an SMTP connection, sends a NOOP, and closes.
Background: When holding an SMTP connection open across many sends (see
OpenSmtpConnection), an idle stretch can cause the server to time out and drop the socket. A periodic NOOP keeps the session active and confirms the server is still responding, so the next SendEmail doesn't fail on a silently-closed connection.Chilkat Rust Downloads
// Demonstrates the MailMan.SmtpNoop method, which sends an SMTP NOOP command to the server.
// NOOP does nothing except elicit a positive response, useful for keeping a connection
// alive or verifying it is still responsive.
let mailman = chilkat::MailMan::new();
// Configure the SMTP server connection.
mailman.set_smtp_host("smtp.example.com");
mailman.set_smtp_port(465);
mailman.set_smtp_ssl(true);
mailman.set_smtp_username("user@example.com");
mailman.set_smtp_password("myPassword");
// Open the SMTP connection.
if mailman.open_smtp_connection().is_err() {
println!("{}", mailman.last_error_text());
return;
}
// Send a NOOP to keep the connection alive.
if mailman.smtp_noop().is_err() {
println!("{}", mailman.last_error_text());
return;
}
if mailman.close_smtp_connection().is_err() {
println!("{}", mailman.last_error_text());
return;
}
println!("SMTP NOOP succeeded.");