Udostępnij za pośrednictwem


Issue accessing Public Folder Store using CDO 1.2.1 for Outlook 2007

If you are using InfoStores collection of CDO 1.2.1 for Outlook 2007 to access Public Folder store and not able to get reference to Public Folder store then here is the explanation of the design change in CDO 1.2.1 from SGriffin’s post@Outlook 2007, Public Folders, MAPI and You.

Basically, Outlook 2007's version of the Exchange provider, emsmdb32, doesn't automatically add the Public Folder store to the message store table of a new profile. Instead, it waits until a successful connection has been made to the Exchange server. If it then detects that the public folders are available, it updates the profile and sends a table notification indicating the availability of Public Folders. This is a change from previous versions of Outlook and from Exchange's version of the provider. We made this change to better support Exchange 2007's Public Folder-less environments.

Here is the vbscript sample code snippet to repro the issue:

NOTE: Following programming examples is for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This sample code assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. This sample code is provided for the purpose of illustration only and is not intended to be used in a production environment.

 'Change Server and User name below
 SERVER = "Server"
 Mailbox = "User"
  
 Set objSession = CreateObject("MAPI.Session")
 objSession.LogOn , "", False, True, , True, SERVER  & Chr(10) & Mailbox
  
     Set objInfoStores = objSession.InfoStores
      For i = 1 To objInfoStores.Count
         If UCase(objInfoStores.Item(i)) = UCase("Public Folders") Then
             Set objInfoStore = objInfoStores.Item(i)
                 msgbox objInfoStore.name 
             Exit For
         End If
     Next
  
 Set objInfoStores= Nothing
 Set objSession=Nothing
  
 The above sample code would not return the name of the Public Folders store to us. 
  
 We need to work around the above issue by creating another session object as per the below code snippet: 
  
 'Change Server and User name below
 SERVER = "Server"
 Mailbox = "User"
  
 Set objSession = CreateObject("MAPI.Session")
 objSession.LogOn , "", False, True, , True, SERVER  & Chr(10) & Mailbox
  
     Set objInfoStores = objSession.InfoStores
      For i = 1 To objInfoStores.Count
         If UCase(objInfoStores.Item(i)) = UCase("Public Folders") Then
             Set objInfoStore = objInfoStores.Item(i)
                 msgbox objInfoStore.name 
             Exit For
         End If
     Next
  
  
 Set objSession2 = CreateObject("MAPI.Session")
 objSession2.LogOn , "", False, False, , True, SERVER  & Chr(10) & Mailbox
  
     Set objInfoStores2 = objSession2.InfoStores
      For i = 1 To objInfoStores2.Count
         If UCase(objInfoStores2.Item(i)) = UCase("Public Folders") Then
             Set objInfoStore2 = objInfoStores2.Item(i)
                 msgbox objInfoStore2.name 
             Exit For
         End If
     Next
  
 Set objInfoStores= Nothing
 Set objSession=Nothing
  
 Set objInfoStores2= Nothing
 Set objSession2=Nothing

 

Note: We are using third parameter as “False” for objSession2.Logon, So that it uses the current shared MAPI session.