简体   繁体   中英

VB Get Outlook Default Mailbox

I need some help in vb. i need a script for outlook 2007 that return the name of pst for default data file. To be clear, the default mailbox when user receive email will be the exchange account. However, some of users use their personal folder as default so that when email arrives, the message automatically go to the appointed personal folder. So my aim is to output the results either the user use exchange account by default or personal folder. If it is personal folder, i want the location/path to the pst. i try to use getdefaultfolder but it returns 'inbox'.

objNS.GetDefaultFolder(olFolderInbox)

PST paths are not exposed by the Outlook Object Model. You can use either Extended MAPI (C++ or Delphi only) or Redemption (any language) to figure out the PST path. See below for an example that reads the RDOPstStore.PstPath property:

  skPstAnsi = 1
  skPstUnicode = 2
  skPrimaryExchangeMailbox = 3
  skDelegateExchangeMailbox = 4
  skPublicFolders = 5
  set Session = CreateObject("Redemption.RDOSession")
  Session.MAPIOBJECT = Application.Session.MAPIOBJECT
  for each Store in Session.Stores
    Debug.Print Store.Name
    if (Store.StoreKind = skPstAnsi) or (Store.StoreKind = skPstUnicode) Then
      Debug.Print Store.PstPath
    ElseIf (Store.StoreKind = skPrimaryExchangeMailbox) or (Store.StoreKind = skDelegateExchangeMailbox) or (Store.StoreKind = skPublicFolders) Then
      Debug.Print Store.ServerDN
    End If
  next

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM