Sample code for 30+ languages & platforms
VBScript

Disconnect from an IMAP Server

See more IMAP Examples

Demonstrates the Chilkat Imap.Disconnect method, which closes the connection to the IMAP server. A failure indicates the connection could not be closed cleanly; the socket is nevertheless no longer intended for use. This example connects, logs in, and then disconnects.

Background: Disconnect closes the underlying TCP socket. It is lower-level than Logout, which first tells the server to end the IMAP session; the tidy shutdown is Logout followed by Disconnect. Always releasing connections matters because servers cap the number of simultaneous IMAP connections per account, and leaked connections can lock you out until they time out.

Chilkat VBScript Downloads

VBScript
Dim fso, outFile
Set fso = CreateObject("Scripting.FileSystemObject")
'Create a Unicode (utf-16) output text file.
Set outFile = fso.CreateTextFile("output.txt", True, True)

success = 0

'  Demonstrates the Imap.Disconnect method, which closes the connection to the IMAP server.

set imap = CreateObject("Chilkat.Imap")

imap.Ssl = 1
imap.Port = 993

success = imap.Connect("imap.example.com")
If (success = 0) Then
    outFile.WriteLine(imap.LastErrorText)
    WScript.Quit
End If

success = imap.Login("user@example.com","myPassword")
If (success = 0) Then
    outFile.WriteLine(imap.LastErrorText)
    WScript.Quit
End If

'  ... perform mailbox operations here ...

'  Close the connection to the IMAP server.
success = imap.Disconnect()
If (success = 0) Then
    outFile.WriteLine(imap.LastErrorText)
    WScript.Quit
End If

outFile.WriteLine("Disconnected from the IMAP server.")

outFile.Close