Sample code for 30+ languages & platforms
Visual FoxPro

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 Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL loImap

lnSuccess = 0

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

loImap = CreateObject('Chilkat.Imap')

loImap.Ssl = 1
loImap.Port = 993

lnSuccess = loImap.Connect("imap.example.com")
IF (lnSuccess = 0) THEN
    ? loImap.LastErrorText
    RELEASE loImap
    CANCEL
ENDIF

lnSuccess = loImap.Login("user@example.com","myPassword")
IF (lnSuccess = 0) THEN
    ? loImap.LastErrorText
    RELEASE loImap
    CANCEL
ENDIF

*  End the authenticated session.
lnSuccess = loImap.Logout()
IF (lnSuccess = 0) THEN
    ? loImap.LastErrorText
    RELEASE loImap
    CANCEL
ENDIF

*  Close the connection.
lnSuccess = loImap.Disconnect()
IF (lnSuccess = 0) THEN
    ? loImap.LastErrorText
    RELEASE loImap
    CANCEL
ENDIF

? "Logged out and disconnected."

RELEASE loImap