Sample code for 30+ languages & platforms
Visual FoxPro

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 Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL loMailman

lnSuccess = 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.

loMailman = CreateObject('Chilkat.MailMan')

*  Configure the SMTP server connection.
loMailman.SmtpHost = "smtp.example.com"
loMailman.SmtpPort = 465
loMailman.SmtpSsl = 1
loMailman.SmtpUsername = "user@example.com"
loMailman.SmtpPassword = "myPassword"

*  Open the SMTP connection.

lnSuccess = loMailman.OpenSmtpConnection()
IF (lnSuccess = 0) THEN
    ? loMailman.LastErrorText
    RELEASE loMailman
    CANCEL
ENDIF

*  Send a NOOP to keep the connection alive.
lnSuccess = loMailman.SmtpNoop()
IF (lnSuccess = 0) THEN
    ? loMailman.LastErrorText
    RELEASE loMailman
    CANCEL
ENDIF

lnSuccess = loMailman.CloseSmtpConnection()
IF (lnSuccess = 0) THEN
    ? loMailman.LastErrorText
    RELEASE loMailman
    CANCEL
ENDIF

? "SMTP NOOP succeeded."

RELEASE loMailman