Sample code for 30+ languages & platforms
Delphi DLL

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 Delphi DLL Downloads

Delphi DLL
var
success: Boolean;
mailman: HCkMailMan;

begin
success := False;

//  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.

mailman := CkMailMan_Create();

//  Configure the SMTP server connection.
CkMailMan_putSmtpHost(mailman,'smtp.example.com');
CkMailMan_putSmtpPort(mailman,465);
CkMailMan_putSmtpSsl(mailman,True);
CkMailMan_putSmtpUsername(mailman,'user@example.com');
CkMailMan_putSmtpPassword(mailman,'myPassword');

//  Open the SMTP connection.

success := CkMailMan_OpenSmtpConnection(mailman);
if (success = False) then
  begin
    Memo1.Lines.Add(CkMailMan__lastErrorText(mailman));
    Exit;
  end;

//  Send a NOOP to keep the connection alive.
success := CkMailMan_SmtpNoop(mailman);
if (success = False) then
  begin
    Memo1.Lines.Add(CkMailMan__lastErrorText(mailman));
    Exit;
  end;

success := CkMailMan_CloseSmtpConnection(mailman);
if (success = False) then
  begin
    Memo1.Lines.Add(CkMailMan__lastErrorText(mailman));
    Exit;
  end;

Memo1.Lines.Add('SMTP NOOP succeeded.');

CkMailMan_Dispose(mailman);