Sample code for 30+ languages & platforms
AutoIt

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

AutoIt
Local $bSuccess = 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.

$oImap = ObjCreate("Chilkat.Imap")

$oImap.Ssl = True
$oImap.Port = 993

$bSuccess = $oImap.Connect("imap.example.com")
If ($bSuccess = False) Then
    ConsoleWrite($oImap.LastErrorText & @CRLF)
    Exit
EndIf

$bSuccess = $oImap.Login("user@example.com","myPassword")
If ($bSuccess = False) Then
    ConsoleWrite($oImap.LastErrorText & @CRLF)
    Exit
EndIf

;  End the authenticated session.
$bSuccess = $oImap.Logout()
If ($bSuccess = False) Then
    ConsoleWrite($oImap.LastErrorText & @CRLF)
    Exit
EndIf

;  Close the connection.
$bSuccess = $oImap.Disconnect()
If ($bSuccess = False) Then
    ConsoleWrite($oImap.LastErrorText & @CRLF)
    Exit
EndIf

ConsoleWrite("Logged out and disconnected." & @CRLF)