Sample code for 30+ languages & platforms
VBScript

Select an IMAP Mailbox

See more IMAP Examples

Demonstrates the Chilkat Imap.SelectMailbox method, which opens a mailbox for read-write access. A mailbox must be selected before message fetch, search, flag, copy, move, or expunge operations that act on messages. This example selects the Inbox.

Background: In IMAP, mail is organized into mailboxes (folders), and most message operations act on the currently selected one — so selecting a mailbox is the required step between logging in and working with messages. SelectMailbox opens it read-write, allowing changes such as setting flags or deleting. When you only need to read and must not alter anything (including the \Seen flag), use ExamineMailbox instead.

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.SelectMailbox method, which opens a mailbox for read-write access.
'  A mailbox must be selected before message fetch, search, flag, copy, move, or expunge
'  operations that act on messages.

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

'  Open the Inbox for read-write access.
success = imap.SelectMailbox("Inbox")
If (success = 0) Then
    outFile.WriteLine(imap.LastErrorText)
    WScript.Quit
End If

outFile.WriteLine("Inbox selected for read-write access.")

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


outFile.Close