MailClient.GetFolderList method


Gets the folders on IMAP4/Exchange server.

[Visual Basic 6.0]
Public Function GetFolders() As FolderCollection
[Visual C++]
public: GetFolderList(IFolderCollection* pVal);

Return Value

A Imap4Folder collection containing the folders on IMAP4/Exchange server.

Example

[Visual Basic 6.0, VBScript, Visual C++, Delphi] The following sample demonstrates how to enumerate all folders on IMAP4 folder. To get the full samples of EAGetMail, please refer to Samples section.

[Visual Basic 6.0]
Public Sub ConnectImapServer(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

On Error GoTo ErrorHandle
    Dim oServer As New EAGetMailObjLib.MailServer
    oServer.Server = Server
    oServer.User = User
    oServer.Password = Password
    oServer.SSLConnection = SSLConnection
    oServer.Protocol = MailServerImap4

    'To manage folder with Exchange Web Service, please change
    'MailServerImap4 to MailServerEWS to MailServer.Protocol

    'To manage folder email with Exchange WebDAV, please change
    'MailServerImap4 to MailServerDAV to MailServer.Protocol

    'Exchange Server supports POP3/IMAP4 protocol as well, but in Exchange 2007
    'or later version, POP3/IMAP4 service is disabled by default. If you don't want to use POP3/IMAP4
    'to download email from Exchange Server, you can use Exchange Web Service(Exchange 2007/2010 or
    'later version) or WebDAV(Exchange 2000/2003) protocol.

    'For Exchange Web Service/WebDAV, please ignore 
    'Port property. But for Exchange Web Service, please set SSLConnection to True

    If oServer.SSLConnection = True Then
        oServer.Port = 993
    Else
        oServer.Port = 143
    End If
    
    Dim oClient As New EAGetMailObjLib.MailClient
    oClient.LicenseCode = "TryIt"
    
    oClient.Connect oServer
    
        'enumerates all folders on IMAP4/Exchange server.
    EnumerateFolder oClient.GetFolderList()
    oClient.Logout
    
    Exit Sub
ErrorHandle:
    MsgBox Err.Description
End Sub

Public Sub EnumerateFolder(oFolders)
    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

        EnumerateFolder oFolder.SubFolderList
    Next   
End Sub


[VBScript] Public Sub ConnectImapServer(ByVal Server, _ ByVal User, _ ByVal Password, _ ByVal SSLConnection) Const MailServerPop3 = 0 Const MailServerImap4 = 1 Const MailServerEWS = 2 Const MailServerDAV = 3 Dim oServer Set oServer = CreateObject("EAGetMailObj.MailServer") oServer.Server = Server oServer.User = User oServer.Password = Password oServer.SSLConnection = SSLConnection oServer.Protocol = MailServerImap4 'To manage folder with Exchange Web Service, please change 'MailServerImap4 to MailServerEWS to MailServer.Protocol 'To manage folder email with Exchange WebDAV, please change 'MailServerImap4 to MailServerDAV to MailServer.Protocol 'Exchange Server supports POP3/IMAP4 protocol as well, but in Exchange 2007 'or later version, POP3/IMAP4 service is disabled by default. If you don't want to use POP3/IMAP4 'to download email from Exchange Server, you can use Exchange Web Service(Exchange 2007/2010 or 'later version) or WebDAV(Exchange 2000/2003) protocol. 'For Exchange Web Service/WebDAV, please ignore 'Port property. But for Exchange Web Service, please set SSLConnection to True If oServer.SSLConnection = True Then oServer.Port = 993 Else oServer.Port = 143 End If Dim oClient Set oClient = CreateObject("EAGetMailObj.MailClient") oClient.LicenseCode = "TryIt" oClient.Connect oServer 'enumerates all folders on IMAP4/Exchange server. EnumerateFolder oClient.GetFolderList() oClient.Logout End Sub Public Sub EnumerateFolder(oFolders) 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 EnumerateFolder oFolder.SubFolderList Next End Sub
[Visual C++] #include "stdafx.h" #include <windows.h> #include "eagetmailobj.tlh" using namespace EAGetMailObjLib; void EnumerateFolder(IFolderCollectionPtr &folders) { 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")); IFolderCollectionPtr subFolders = oFolder->SubFolderList; EnumerateFolder(subFolders); } } void ConnectImap4Server(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; try { IMailServerPtr oServer = NULL; oServer.CreateInstance(__uuidof(EAGetMailObjLib::MailServer)); oServer->Server = lpszServer; oServer->User = lpszUser; oServer->Password = lpszPassword; oServer->SSLConnection = SSLConnection; oServer->Protocol = MailServerImap4; //To manage folder with Exchange Web Service, please change //MailServerImap4 to MailServerEWS to MailServer.Protocol //To manage folder email with Exchange WebDAV, please change //MailServerImap4 to MailServerDAV to MailServer.Protocol //Exchange Server supports POP3/IMAP4 protocol as well, but in Exchange 2007 //or later version, POP3/IMAP4 service is disabled by default. If you don't want to use POP3/IMAP4 //to download email from Exchange Server, you can use Exchange Web Service(Exchange 2007/2010 or //later version) or WebDAV(Exchange 2000/2003) protocol. //For Exchange Web Service/WebDAV, please ignore //Port property. But for Exchange Web Service, please set SSLConnection to True if(SSLConnection == VARIANT_TRUE) oServer->Port = 993; else oServer->Port = 143; IMailClientPtr oClient = NULL; oClient.CreateInstance(__uuidof(EAGetMailObjLib::MailClient)); oClient->LicenseCode = _T("TryIt"); oClient->Connect(oServer); IFolderCollectionPtr folders = oClient->GetFolderList(); //enumerates all folders on IMAP4/Exchange server. EnumerateFolder(folders); } catch(_com_error &ep) { ::_tprintf(_T("%s\r\n"), (TCHAR*)ep.Description()); } ::CoUninitialize(); }
[Delphi] const const int MailServerPop3 = 0; const int MailServerImap4 = 1; const int MailServerEWS = 2; const int MailServerDAV = 3; procedure EnumerateFolder(folders: IFolderCollection); var folder: IImap4Folder; i: integer; begin for i := 0 to folders.Count - 1 do begin folder := folders.Item[i]; ShowMessage('Name: ' + folder.Name); ShowMessage('FullPath: ' + folder.FullPath); ShowMessage('LocalPath: ' + folder.LocalPath); ShowMessage('Flags: ' + folder.IMAP4FolderFlags); if folder.Subscribed then ShowMessage('Subscribed: True') else ShowMessage('Subscribed: False'); EnumerateFolder(folder.SubFolderList); end; end; procedure ConnectImap4Server(server: WideString; user: WideString; password: WideString; useSslConnection: Boolean); var oServer: TMailServer; oClient: TMailClient; folders: IFolderCollection; begin try // set current thread code page to system default code page. SetThreadLocale(GetSystemDefaultLCID()); //To manage folder with Exchange Web Service, please change //MailServerImap4 to MailServerEWS to MailServer.Protocol //To manage folder email with Exchange WebDAV, please change //MailServerImap4 to MailServerDAV to MailServer.Protocol //Exchange Server supports POP3/IMAP4 protocol as well, but in Exchange 2007 //or later version, POP3/IMAP4 service is disabled by default. If you don't want to use POP3/IMAP4 //to download email from Exchange Server, you can use Exchange Web Service(Exchange 2007/2010 or //later version) or WebDAV(Exchange 2000/2003) protocol. //For Exchange Web Service/WebDAV, please ignore //Port property. But for Exchange Web Service, please set SSLConnection to True oServer := TMailServer.Create(Application); oServer.Server := server; oServer.User := user; oServer.Password := password; oServer.Protocol := MailServerImap4; // Enable SSL/TLS Connection, most modern email server require SSL/TLS connection by default. oServer.SSLConnection := useSslConnection; if useSslConnection then begin // Set 993 SSL IMAP port oServer.Port := 993; end else begin // Set 143 IMAP port oServer.Port := 143; end; oClient := TMailClient.Create(Application); oClient.LicenseCode := 'TryIt'; oClient.Connect1(oServer.DefaultInterface); ShowMessage('Connected!'); folders := oClient.GetFolderList(); EnumerateFolder(folders); except on ep:Exception do ShowMessage('Error: ' + ep.Message); end; end;

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++