Retrieves all public folders from MS Exchange Server 2007 or later version.
[Visual Basic 6.0] Public Function GetEWSPublicFolderList( _ ) As FolderCollection
[Visual C++] public: HRESULT GetEWSPublicFolderList( IFolderCollection* 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
'enumerates all public folders on MS Exchange server.
EnumerateFolder oClient.GetEWSPublicFolderList(), oClient
oClient.Logout
Exit Sub
ErrorHandle:
MsgBox Err.Description
End Sub
Public Sub EnumerateFolder(oFolders, oClient)
Dim i As Integer
For i = 0 To oFolders.Count - 1
Dim oFolder As EAGetMailObjLib.Imap4Folder
Set oFolder = oFolders.Item(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)
s = s & "Flags: " & oFolder.IMAP4FolderFlags & Chr(13) & Chr(10)
s = s & "Subscribed: " & oFolder.Subscribed & 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.SubFolderList
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
'enumerates all public folders on MS Exchange server.
EnumerateFolder oClient.GetEWSPublicFolderList(), oClient
oClient.Logout
End Sub
Public Sub EnumerateFolder(oFolders, oClient)
Dim i
For i = 0 To oFolders.Count - 1
Dim oFolder
Set oFolder = oFolders.Item(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)
s = s & "Flags: " & oFolder.IMAP4FolderFlags & Chr(13) & Chr(10)
s = s & "Subscribed: " & oFolder.Subscribed & 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.SubFolderList
Next
End Sub
[Visual C++]
#include "stdafx.h"
#include <windows.h>
#include "eagetmailobj.tlh"
using namespace EAGetMailObjLib;
void EnumerateFolder(IFolderCollectionPtr &folders, IMailClientPtr &oClient)
{
for(long i = 0; i < folders->Count; i++)
{
IImap4FolderPtr oFolder = folders->GetItem(i);
_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);
_tprintf(_T("Flags: %s\r\n"), (TCHAR*)oFolder->IMAP4FolderFlags);
if(oFolder->Subscribed == VARIANT_TRUE)
_tprintf(_T("Subscribed: True\r\n\r\n"));
else
_tprintf(_T("Subscribed: False\r\n\r\n"));
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
IFolderCollectionPtr subFolders = oFolder->SubFolderList;
EnumerateFolder(subFolders);
}
}
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);
IFolderCollectionPtr folders = oClient->GetEWSPublicFolderList();
//enumerates all public folders on MS Exchange server.
EnumerateFolder(folders, 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++