Sample code for 30+ languages & platforms
DataFlex

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

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoImap
    String sTemp1

    Move False To iSuccess

    //  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.

    Get Create (RefClass(cComChilkatImap)) To hoImap
    If (Not(IsComObjectCreated(hoImap))) Begin
        Send CreateComObject of hoImap
    End

    Set ComSsl Of hoImap To True
    Set ComPort Of hoImap To 993

    Get ComConnect Of hoImap "imap.example.com" To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoImap To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComLogin Of hoImap "user@example.com" "myPassword" To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoImap To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    //  End the authenticated session.
    Get ComLogout Of hoImap To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoImap To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    //  Close the connection.
    Get ComDisconnect Of hoImap To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoImap To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Showln "Logged out and disconnected."


End_Procedure