Sample code for 30+ languages & platforms
Java

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 Java Downloads

Chilkat2 Java
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.MailMan;

public class ChilkatExample {

    public static void main(String[] args) {
        // 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 mailman = new MailMan();

        // Configure the SMTP server connection.
        mailman.setSmtpHost("smtp.example.com");
        mailman.setSmtpPort(465);
        mailman.setSmtpSsl(true);
        mailman.setSmtpUsername("user@example.com");
        mailman.setSmtpPassword("myPassword");

        // Open the SMTP connection.

        try {
            mailman.openSmtpConnection();

            // Send a NOOP to keep the connection alive.
            mailman.smtpNoop();

            mailman.closeSmtpConnection();
        } catch (ChilkatException e) {
            System.out.println(e.getLastErrorText());
            return;
        }

        System.out.println("SMTP NOOP succeeded.");
    }
}