MailClient.QueryEWSPublicFolders Method


Retrieves all public folders from MS Exchange Server 2007 or later version.

[Visual Basic]
Public Function QueryEWSPublicFolders( _
) As  Imap4Folder()
[C#]
public Imap4Folder [] QueryEWSPublicFolders(
);
[C++]
public: array<Imap4Folder^> QueryEWSPublicFolders(
);
[JScript]
public function QueryEWSPublicFolders( 
) : Imap4Folder [];

Return Value

A Imap4Folder array containing the public folders on MS Exchange Server 2007 or later version.

Remarks

Since Exchange 2007 or later version (2007/2010/2013/2016/2019), IMAP4 protocol does not expose public folders to mail client. If you want to access public folders on MS Exchange 2007/2010/2013/2016/2019 or later version, you should use Exchange Web Service(EWS) protocol and MailClient.QueryEWSPublicFolders Method.

Example

[Visual Basic, C#, C++] The following example demonstrates how to retrieve public folders/emails from MS Exchange Server 2007/2010/2013/2016/2019 with EAGetMail POP3 & IMAP Component. To get the full samples of EAGetMail, please refer to Samples section.

[VB - Retrieve public folders on Exchange Server]
Imports System
Imports System.Globalization
Imports System.IO
Imports System.Text
Imports EAGetMail

Public Class TestClass
    Shared Sub EnumerateFolder(ByVal folders() As Imap4Folder, ByRef oClient As MailClient)
        For i As Integer = 0 To folders.Length - 1
            Dim folder As Imap4Folder = folders(i)
            Console.WriteLine("Name: {0}", folder.Name)
            Console.WriteLine("FullPath: {0}", folder.FullPath)
            Console.WriteLine("LocalPath: {0}", folder.LocalPath)

            ' Select current folder
            oClient.SelectFolder(folder)

            ' Get email list in current selected folder.
            Dim infos() As MailInfo = oClient.GetMailInfos()
            Console.WriteLine("{0} mailbox has {1} emails", oClient.SelectedFolder, infos.Length)

            EnumerateFolder(folder.SubFolders, oClient)
        Next
    End Sub

    Public Sub RetrievePublicFolder(server As String, user As String, password As String, useSsl As Boolean)

        Try
            ' Only ExchangeEWS Protocol supports this feature
            ' EWS requires SSL by default, set useSsl to true
            Dim oServer As New MailServer(server, user, password, useSsl,
            ServerAuthType.AuthLogin, ServerProtocol.ExchangeEWS)

            Dim oClient As New MailClient("TryIt")
            oClient.Connect(oServer)

            Dim folders() As Imap4Folder = oClient.QueryEWSPublicFolders()

            ' Enumerates all public folders on MS Exchange server.
            EnumerateFolder(folders, oClient)

            oClient.Logout()
        Catch ep As Exception
            Console.WriteLine(ep.Message)
        End Try
    End Sub

End Class


[C# - Retrieve public folders on Exchange Server] using System; using System.IO; using System.Globalization; using System.Text; using EAGetMail; class TestClass { static void EnumerateFolder(Imap4Folder[] folders, ref MailClient oClient) { for (int i = 0; i < folders.Length; i++) { Imap4Folder folder = folders[i]; Console.WriteLine("Name: {0}", folder.Name); Console.WriteLine("FullPath: {0}", folder.FullPath); Console.WriteLine("LocalPath: {0}", folder.LocalPath); // Select current folder oClient.SelectFolder(folder); // Get email list in current selected folder. MailInfo[] infos = oClient.GetMailInfos(); Console.WriteLine("{0} mailbox has {1} email(s)", oClient.SelectedFolder, infos.Length); EnumerateFolder(folder.SubFolders, ref oClient); } } public void RetrievePublicFolders(string server, string user, string password, bool useSsl) { try { // Only ExchangeEWS Protocol supports this feature // EWS requires SSL by default, set useSsl to true MailServer oServer = new MailServer(server, user, password, useSsl, ServerAuthType.AuthLogin, ServerProtocol.ExchangeEWS); MailClient oClient = new MailClient("TryIt"); oClient.Connect(oServer); Imap4Folder[] folders = oClient.QueryEWSPublicFolders(); // Enumerates all public folders on MS Exchange server. EnumerateFolder(folders, ref oClient); oClient.Logout(); } catch (Exception ep) { Console.WriteLine(ep.Message); } } }
[C++/CLI - Retrieve public folders on Exchange Server] using namespace System; using namespace System::Globalization; using namespace System::IO; using namespace EAGetMail; //add EAGetMail namespace static Void EnumerateFolder(array<Imap4Folder^>^folders, MailClient ^oClient) { for (int i = 0; i < folders->Length; i++) { Imap4Folder ^folder = folders[i]; Console::WriteLine("Name: {0}", folder->Name); Console::WriteLine("FullPath: {0}", folder->FullPath); Console::WriteLine("LocalPath: {0}", folder->LocalPath); // Select current folder oClient->SelectFolder(folder); // Get email list in current selected folder. array<MailInfo^>^infos = oClient->GetMailInfos(); Console::WriteLine("{0} mailbox has {1} emails", oClient->SelectedFolder, infos->Length); EnumerateFolder(folder->SubFolders, oClient); } } Void RetrievePublicFolders(String^ server, String^ user, String^ password, bool useSsl) { try { // Only ExchangeEWS Protocol supports this feature // EWS requires SSL by default, so set useSsl to true MailServer ^oServer = gcnew MailServer(server, user, password, useSsl, ServerAuthType::AuthLogin, ServerProtocol::ExchangeEWS); MailClient ^oClient = gcnew MailClient("TryIt"); oClient->Connect(oServer); array<Imap4Folder^>^folders = oClient->QueryEWSPublicFolders(); // Enumerates all public folders on MS Exchange server. EnumerateFolder(folders, oClient); oClient->Logout(); } catch (Exception ^ep) { Console::WriteLine(ep->Message); } }

See Also

MailClient.Imap4Folders Property
MailClient.CreateFolder Method
MailClient.DeleteFolder Method
MailClient.Move Method
MailClient.Copy Method
MailClient.SelectFolder Method

Online Tutorials

Manage Mail Folders in C#
Manage Mail Folders in VB
Manage Mail Folders in C++/CLI