Sample code for 30+ languages & platforms
Swift

Send a Raw IMAP Command

See more IMAP Examples

Demonstrates the Chilkat Imap.SendRawCommand method, which sends raw IMAP command text and returns the raw server response. Pass the command itself (such as NOOP) without an IMAP tag — Chilkat adds the tag automatically. This example sends a raw NOOP.

Background: Every IMAP command a client sends is prefixed with a short unique tag (like a001) so the client can match the tagged completion response to the command it issued. SendRawCommand handles that tagging for you and returns the server's reply verbatim — an escape hatch for issuing a command Chilkat doesn't wrap directly, or a server-specific extension, without leaving the established authenticated session.

Chilkat Swift Downloads

Swift

func chilkatTest() {
    var success: Bool = false

    //  Demonstrates the Imap.SendRawCommand method, which sends raw IMAP command text and returns
    //  the raw server response.  Pass the command itself (such as NOOP) without an IMAP tag --
    //  Chilkat adds the tag automatically.

    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 raw IMAP command and read the raw response.
    var response: String? = imap.sendRawCommand(rawCommand: "NOOP")
    if imap.lastMethodSuccess == false {
        print("\(imap.lastErrorText!)")
        return
    }

    print("\(response!)")

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


}