Sample code for 30+ languages & platforms
Swift

Check Whether the IMAP Session Is Authenticated

See more IMAP Examples

Demonstrates the Chilkat Imap.IsLoggedIn method, which indicates whether this object is in an authenticated IMAP session. It reports the last known state and does not send a command to the server. This example connects, logs in, and checks the state.

Background: An IMAP session has two levels: connected (the TCP/TLS link is up) and authenticated (login succeeded). IsLoggedIn reports the second — useful when reusing a long-lived Imap object to decide whether you still need to log in before performing mailbox operations. Like IsConnected, it reflects cached state and doesn't contact the server.

Chilkat Swift Downloads

Swift

func chilkatTest() {
    var success: Bool = false

    //  Demonstrates the Imap.IsLoggedIn method, which indicates whether this object is in an
    //  authenticated IMAP session.  It reports the last known state and does not send a command
    //  to the server.

    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
    }

    //  Check whether the session is authenticated.
    var loggedIn: Bool = imap.isLoggedIn()
    if loggedIn == true {
        print("The session is authenticated.")
    }
    else {
        print("The session is not authenticated.")
    }

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


}