Sample code for 30+ languages & platforms
VBScript

Open an IMAP Mailbox Read-Only

See more IMAP Examples

Demonstrates the Chilkat Imap.ExamineMailbox method, which opens a mailbox as read-only. Use it instead of SelectMailbox when the application must not change message state, such as the \Seen flag. This example examines the Inbox.

Background: Reading a message can have a side effect: fetching its body normally sets the \Seen flag, marking it as read. ExamineMailbox corresponds to IMAP's EXAMINE command, which opens the mailbox in a read-only mode where no such changes are made — ideal for scanning, indexing, or backup tools that must leave the user's mailbox exactly as they left it.

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.ExamineMailbox method, which opens a mailbox as read-only.  Use this
'  instead of SelectMailbox when the application must not change message state (such as the
'  \Seen flag).

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 as read-only.
success = imap.ExamineMailbox("Inbox")
If (success = 0) Then
    outFile.WriteLine(imap.LastErrorText)
    WScript.Quit
End If

outFile.WriteLine("Inbox opened read-only.")

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


outFile.Close