MailBee.NET Objects 4.0

Imap.SelectFolder Method 

Selects the specified folder (mailbox in IMAP4 terms) for read-write access.

public bool SelectFolder(
   string folderName
);

Parameters

folderName
The full name of the folder to be selected.

Return Value

true if the folder was selected successfully; otherwise, false.

Remarks

To select the folder for read-only access, the developer should use ExamineFolder method.

The developer should specify the full name of the folder (including all parent folders' names if the folder is subfolder of another existing folder). See CreateFolder topic for details regarding folder names.

Exceptions

Exception TypeCondition
MailBeeExceptionAn error occurred and ThrowExceptions is true.

Example

This sample connects to the IMAP4 server, logs in the mail account, selects Inbox folder, and marks all messages as seen (read).

[C#]
using System;
using MailBee;
using MailBee.ImapMail;

class Sample
{
     static void Main(string[] args)
     {
         Imap imp = new Imap();

         // Connect to the server and log in the account.
         imp.Connect("imap.company.com");
         imp.Login("jdoe", "secret");

         // Select the folder in read-only mode.
         imp.SelectFolder("Inbox");

         imp.SetMessageFlags(Imap.AllMessages, false,
             SystemMessageFlags.Seen, MessageFlagAction.Add);

         imp.Disconnect();
     }
}
[Visual Basic]
Imports System
Imports MailBee
Imports MailBee.ImapMail

Module Sample

    Sub Main(ByVal args As String())
        ' The actual code (put it into a method of your class)
        Dim imp As New Imap

        ' Connect to the server and log in the account.
        imp.Connect("imap4.company.com")
        imp.Login("jdoe@company.com", "secret")

        ' Select the folder in read-only mode.
        imp.SelectFolder("Inbox")

        If imp.MessageCount > 0 Then
            ' Download and save last message into a file.
            ' If the message is recent, it won't loose \Recent flag.
            Dim msg As MailBee.Mime.MailMessage = _
                imp.DownloadEntireMessage(imp.MessageCount, False)
            msg.SaveMessage("C:\Temp\msg.eml")
        End If

        imp.Disconnect()
    End Sub
End Module

See Also

Imap Class | MailBee.ImapMail Namespace | ExamineFolder | IsFolderSelected