Retrieves all public folders from MS Exchange Server 2007 or later version.
This method is obsoleted by GetEWSPublicFolderList
[Visual Basic 6.0] Public Function QueryEWSPublicFolders( _ ) As Variant
[Visual C++] public: HRESULT QueryEWSPublicFolders( VARIANT* pVal );
Return Value
Remarks
Since Exchange 2007 or later version (2010/203), IMAP4 protocol does not expose public folders to mail client. If you want to access public folders on MS Exchange 2007/2010/2013 or later version, you should use Exchange Web Service(EWS) protocol and MailClient.QueryEWSPublicFolders Method.
Example
[Visual Basic, VBScript, VC++] The following example demonstrates how to retrieve public folders/emails from MS Exchange Server 2007/2010/2013 with EAGetMail POP3 & IMAP Component. To get the full samples of EAGetMail, please refer to Samples section.
[Visual Basic 6.0] Public Sub Retrieve_Public_Folders(ByVal Server As String, _ ByVal User As String, _ ByVal Password As String, _ ByVal SSLConnection As Boolean) Const MailServerPop3 = 0 Const MailServerImap4 = 1 Const MailServerEWS = 2 Const MailServerDAV = 3 Const MailServerMsGraph = 4 ' Only ExchangeEWS Protocol supports this feature ' and also set sslConnection to True On Error GoTo ErrorHandle Dim oServer As New EAGetMailObjLib.MailServer oServer.Server = Server oServer.User = User oServer.Password = Password oServer.SSLConnection = True oServer.Protocol = MailServerEWS Dim oClient As New EAGetMailObjLib.MailClient oClient.LicenseCode = "TryIt" oClient.Connect oServer Dim arFolder arFolder = oClient.QueryEWSPublicFolders() 'enumerates all public folders on MS Exchange server. EnumerateFolder arFolder, oClient oClient.Logout Exit Sub ErrorHandle: MsgBox Err.Description End Sub Public Sub EnumerateFolder(oFolders, oClient) Dim i, count As Integer count = UBound(oFolders) For i = LBound(oFolders) To count Dim oFolder As EAGetMailObjLib.Imap4Folder Set oFolder = oFolders(i) Dim s s = "Name: " & oFolder.Name & Chr(13) & Chr(10) s = s & "FullPath: " & oFolder.FullPath & Chr(13) & Chr(10) s = s & "LocalPath: " & oFolder.LocalPath & Chr(13) & Chr(10) MsgBox s oClient.SelectFolder oFolder MsgBox oClient.SelectedFolder 'then you can use oClient.GetMailInfos to retrieve the emails in this folder EnumerateFolder oFolder.SubFolders, oClient Next End Sub
[VBScript] Public Sub Retrieve_Public_Folders(ByVal Server, _ ByVal User, _ ByVal Password, _ ByVal SSLConnection) Const MailServerPop3 = 0 Const MailServerImap4 = 1 Const MailServerEWS = 2 Const MailServerDAV = 3 Const MailServerMsGraph = 4 ' Only ExchangeEWS Protocol supports this feature ' and also set sslConnection to True Dim oServer Set oServer = CreateObject("EAGetMailObj.MailServer") oServer.Server = Server oServer.User = User oServer.Password = Password oServer.SSLConnection = True oServer.Protocol = MailServerEWS Dim oClient Set oClient = CreateObject("EAGetMailObj.MailClient") oClient.LicenseCode = "TryIt" oClient.Connect oServer Dim arFolder arFolder = oClient.QueryEWSPublicFolders() 'enumerates all public folders on MS Exchange server. EnumerateFolder arFolder, oClient oClient.Logout End Sub Public Sub EnumerateFolder(oFolders, oClient) Dim i, count count = UBound(oFolders) For i = LBound(oFolders) To count Dim oFolder Set oFolder = oFolders(i) Dim s s = "Name: " & oFolder.Name & Chr(13) & Chr(10) s = s & "FullPath: " & oFolder.FullPath & Chr(13) & Chr(10) s = s & "LocalPath: " & oFolder.LocalPath & Chr(13) & Chr(10) MsgBox s oClient.SelectFolder oFolder MsgBox oClient.SelectedFolder 'then you can use oClient.GetMailInfos to retrieve the emails in this folder EnumerateFolder oFolder.SubFolders, oClient Next End Sub
[Visual C++] #include "stdafx.h" #include <windows.h> #include "eagetmailobj.tlh" using namespace EAGetMailObjLib; void EnumerateFolder(_variant_t &arFolder, IMailClientPtr &oClient) { SAFEARRAY *psa = arFolder.parray; LONG UBound = 0, LBound = 0; SafeArrayGetLBound(psa, 1, &LBound); SafeArrayGetUBound(psa, 1, &UBound); for( long i = LBound; i <= UBound; i++ ) { _variant_t vt; SafeArrayGetElement(psa, &i, &vt); IImap4FolderPtr oFolder; vt.pdispVal->QueryInterface(__uuidof(IImap4Folder), (void**)&oFolder); _tprintf(_T("Name: %s\r\n"), (TCHAR*)oFolder->Name); _tprintf(_T("FullPath: %s\r\n"), (TCHAR*)oFolder->FullPath); _tprintf(_T("LocalPath: %s\r\n"), (TCHAR*)oFolder->LocalPath); oClient->SelectFolder(oFolder); _tprintf(_T("Selected folder: %sr\n"), (const TCHAR*)oClient->SelectedFolder); // then you can use oClient.GetMailInfos to retrieve the emails in this folder _variant_t vtFolders = oFolder->SubFolders; EnumerateFolder( vtFolders, oClient ); } } void Retrieve_Public_Folders(LPCTSTR lpszServer, LPCTSTR lpszUser, LPCTSTR lpszPassword, VARIANT_BOOL SSLConnection) { ::CoInitialize( NULL ); const int MailServerPop3 = 0; const int MailServerImap4 = 1; const int MailServerEWS = 2; const int MailServerDAV = 3; const int MailServerMsGraph = 4; try { IMailServerPtr oServer = NULL; oServer.CreateInstance(__uuidof(EAGetMailObjLib::MailServer)); // Only ExchangeEWS Protocol supports this feature // and also set SSLConnection to True oServer->Server = lpszServer; oServer->User = lpszUser; oServer->Password = lpszPassword; oServer->SSLConnection = VARIANT_TRUE; oServer->Protocol = MailServerEWS; IMailClientPtr oClient = NULL; oClient.CreateInstance(__uuidof(EAGetMailObjLib::MailClient)); oClient->LicenseCode = _T("TryIt"); oClient->Connect(oServer); _variant_t vtFolders = oClient->Imap4Folders; //enumerates all public folders on MS Exchange server. EnumerateFolder(vtFolders, oClient); } catch( _com_error &ep ) { ::_tprintf( _T("%s\r\n"), (TCHAR*)ep.Description() ); } ::CoUninitialize(); }
See Also
MailClient.CreateFolder Method
MailClient.DeleteFolder Method
MailClient.Move Method
MailClient.Copy Method
MailClient.SelectFolder Method
Online Tutorials
Manage Mail Folders in VB6
Manage Mail Folders in Delphi
Manage Mail Folders in VC++