Sample code for 30+ languages & platforms
Go

Log Out of an IMAP Server

See more IMAP Examples

Demonstrates the Chilkat Imap.Logout method, which sends the IMAP LOGOUT command and ends the authenticated session. The server normally closes the connection as part of a successful logout. This example connects, logs in, logs out, and disconnects.

Background: LOGOUT is the polite way to end an IMAP session — it tells the server you are finished so it can release the session's resources and close the socket gracefully, rather than treating the disconnect as an abrupt drop. It is the counterpart to Login; calling Disconnect afterward ensures the local socket is fully closed.

Chilkat Go Downloads

Go
    success := false

    //  Demonstrates the Imap.Logout method, which sends the IMAP LOGOUT command and ends the
    //  authenticated session.  The server normally closes the connection as part of a successful
    //  logout.

    imap := chilkat.NewImap()

    imap.SetSsl(true)
    imap.SetPort(993)

    success = imap.Connect("imap.example.com")
    if success == false {
        fmt.Println(imap.LastErrorText())
        imap.DisposeImap()
        return
    }

    success = imap.Login("user@example.com","myPassword")
    if success == false {
        fmt.Println(imap.LastErrorText())
        imap.DisposeImap()
        return
    }

    //  End the authenticated session.
    success = imap.Logout()
    if success == false {
        fmt.Println(imap.LastErrorText())
        imap.DisposeImap()
        return
    }

    //  Close the connection.
    success = imap.Disconnect()
    if success == false {
        fmt.Println(imap.LastErrorText())
        imap.DisposeImap()
        return
    }

    fmt.Println("Logged out and disconnected.")

    imap.DisposeImap()