Sample code for 30+ languages & platforms
VBScript

End IMAP IDLE Mode

See more IMAP Examples

Demonstrates the Chilkat Imap.IdleDone method, which ends IDLE mode by sending the protocol's DONE continuation. It takes no arguments. The authenticated connection remains open and usable afterward.

Background: While IDLE is active the connection is dedicated to receiving push notifications, so any command that needs to talk to the server — fetching a message, setting a flag — must wait until IDLE ends. IdleDone cleanly exits IDLE without dropping the login, so the same connection can immediately be reused. Calling it when IDLE is not active fails.

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.IdleDone method, which ends IMAP IDLE mode by sending the DONE
'  continuation.  It takes no arguments.  The authenticated connection remains open and usable.

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

success = imap.SelectMailbox("Inbox")
If (success = 0) Then
    outFile.WriteLine(imap.LastErrorText)
    WScript.Quit
End If

success = imap.IdleStart()
If (success = 0) Then
    outFile.WriteLine(imap.LastErrorText)
    WScript.Quit
End If

'  Check once for any updates that arrived.
timeoutMs = 5000
updates = imap.IdleCheck(timeoutMs)
If (imap.LastMethodSuccess = 0) Then
    outFile.WriteLine(imap.LastErrorText)
    WScript.Quit
End If

outFile.WriteLine(updates)

'  End IDLE so that ordinary IMAP commands can be sent again on the same connection.
success = imap.IdleDone()
If (success = 0) Then
    outFile.WriteLine(imap.LastErrorText)
    WScript.Quit
End If

outFile.WriteLine("IDLE mode ended.")

success = imap.Disconnect()
If (success = 0) Then
    outFile.WriteLine(imap.LastErrorText)
    WScript.Quit
End If


outFile.Close