Tcl
Tcl
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 Tcl Downloads
load ./chilkat.dll
set success 0
# 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.
set mailman [new_CkMailMan]
# Configure the SMTP server connection.
CkMailMan_put_SmtpHost $mailman "smtp.example.com"
CkMailMan_put_SmtpPort $mailman 465
CkMailMan_put_SmtpSsl $mailman 1
CkMailMan_put_SmtpUsername $mailman "user@example.com"
CkMailMan_put_SmtpPassword $mailman "myPassword"
# Open the SMTP connection.
set success [CkMailMan_OpenSmtpConnection $mailman]
if {$success == 0} then {
puts [CkMailMan_lastErrorText $mailman]
delete_CkMailMan $mailman
exit
}
# Send a NOOP to keep the connection alive.
set success [CkMailMan_SmtpNoop $mailman]
if {$success == 0} then {
puts [CkMailMan_lastErrorText $mailman]
delete_CkMailMan $mailman
exit
}
set success [CkMailMan_CloseSmtpConnection $mailman]
if {$success == 0} then {
puts [CkMailMan_lastErrorText $mailman]
delete_CkMailMan $mailman
exit
}
puts "SMTP NOOP succeeded."
delete_CkMailMan $mailman