Sample code for 30+ languages & platforms
Swift

Send an IMAP NOOP Command

See more IMAP Examples

Demonstrates the Chilkat Imap.Noop method, which sends the IMAP NOOP command and waits for the server response. It is useful for verifying that an existing authenticated connection is still responsive, and for keeping the connection alive. This example connects, logs in, and sends a NOOP.

Background: Because NOOP makes an actual round trip to the server, a successful reply proves the connection is genuinely alive — something the cached IsConnected cannot. It doubles as a keep-alive to prevent an idle session from timing out. In IMAP, NOOP also gives the server a chance to report changes in the selected mailbox, such as newly-arrived messages.

Chilkat Swift Downloads

Swift

func chilkatTest() {
    var success: Bool = false

    //  Demonstrates the Imap.Noop method, which sends the IMAP NOOP command and waits for the
    //  server response.  It is useful for verifying that an existing authenticated connection is
    //  still responsive and for keeping the connection alive.

    let imap = CkoImap()!

    imap.ssl = true
    imap.port = 993

    success = imap.connect(hostname: "imap.example.com")
    if success == false {
        print("\(imap.lastErrorText!)")
        return
    }

    success = imap.login(login: "user@example.com", password: "myPassword")
    if success == false {
        print("\(imap.lastErrorText!)")
        return
    }

    //  Send a NOOP round trip to confirm the connection is alive.
    success = imap.noop()
    if success == false {
        print("\(imap.lastErrorText!)")
        return
    }

    print("IMAP NOOP succeeded.")

    success = imap.disconnect()
    if success == false {
        print("\(imap.lastErrorText!)")
        return
    }


}