2016-02-14 22 views
0

我有我的Outlook 2010,外接(C#),許多文件夾。他們在我的私人郵箱或我的共享郵箱中。如何獲取文件夾項目關聯的發件人電子郵件地址? (VSTO /展望2010/MAPI)

現在我正在尋找一個解決方案找出來,如何獲得一個專用文件夾相關聯的權限的電子郵件地址(發件人/接受者)。它可以是我的私人或任何我的共享郵箱中的任何文件夾。

我想,也許我可以使用文件夾項目中的EntryId/StoreId來標識相應的電子郵件地址。

我已經知道,我可以從任何郵件中獲取電子郵件地址,但我不想尋找這個解決方案。

+0

你的意思是你綁找出父Exchange郵箱的主人嗎? –

+0

是的,我的意思是。 – creg

回答

0

我喜歡回答我自己的問題:我想我已經找到一個合理的解決方案。

我不把裏面的函數任何異常,我這樣做,從外面。

private string GetSMTPAddressByFolderItem(Outlook.MAPIFolder mapiFolder) 
    { 

     string PR_MAILBOX_OWNER_ENTRYID = @"http://schemas.microsoft.com/mapi/proptag/0x661B0102"; 
     string PR_SMTP_ADDRESS = @"http://schemas.microsoft.com/mapi/proptag/0x39FE001E"; 

     Outlook.Store store = null; 
     Outlook.NameSpace ns = null; 
     Outlook.AddressEntry sender = null; 
     Outlook._ExchangeUser exchUser = null; 

     try 
     { 
      if (mapiFolder == null) 
      { 
       return null; 
      } 

      // Get the parent store. 
      store = mapiFolder.Store; 

      string storeOwnerEntryId = store.PropertyAccessor.BinaryToString(store.PropertyAccessor.GetProperty(PR_MAILBOX_OWNER_ENTRYID)) as string; 
      ns = Application.GetNamespace(Constants.OL_NAMESPACE); // i.e. "MAPI" 

      sender = ns.GetAddressEntryFromID(storeOwnerEntryId); 

      if (sender != null) 
      { 
       if (sender.AddressEntryUserType == Outlook.OlAddressEntryUserType.olExchangeUserAddressEntry || 
        sender.AddressEntryUserType == Outlook.OlAddressEntryUserType.olExchangeRemoteUserAddressEntry) 
       { 
        exchUser = sender.GetExchangeUser(); 

        if (exchUser != null) 
        { 
         return exchUser.PrimarySmtpAddress; 
        } 
        else 
        { 
         return null; 
        } 
       } 
       else 
       { 
        return sender.PropertyAccessor.GetProperty(PR_SMTP_ADDRESS) as string; 
       } 
      } 

      return null; 
     } 
     finally 
     { 
      if (ns != null) 
      { 
       Marshal.ReleaseComObject(ns); 
       ns = null; 
      } 
      if (store != null) 
      { 
       Marshal.ReleaseComObject(store); 
       store = null; 
      } 
      if (sender != null) 
      { 
       Marshal.ReleaseComObject(sender); 
       sender = null; 
      } 
      if (exchUser != null) 
      { 
       Marshal.ReleaseComObject(exchUser); 
       exchUser = null; 
      } 
     } 
    } 
+0

PR_MAILBOX_OWNER_ENTRYID只在在線模式。緩存模式不公開它。 –

+0

感謝您的注意,我們不使用緩存模式。 – creg

0

你可以嘗試

  1. 檢索使用Store.PropertyAccessor.GetProperty店裏PR_MAILBOX_OWNER_ENTRYID屬性,但它僅通過在線商店暴露,緩存店不公開它。

  2. 解析Exchange存儲條目標識以提取商店所有者的DN,然後創建GAL用戶條目標識。

  3. 你可以看一下配置文件數據,找到店老闆條目ID。

如果使用Redemption是一個選項,它暴露了RDOExchangeMailboxStore .Owner屬性:

skPrimaryExchangeMailbox = 3 
    skDelegateExchangeMailbox = 4 
    set Session = CreateObject("Redemption.RDOSession") 
    Session.MAPIOBJECT = Application.Session.MAPIOBJECT 
    for each Store in Session.Stores 
    If (Store.StoreKind = skPrimaryExchangeMailbox) or (Store.StoreKind = skDelegateExchangeMailbox) Then 
     MsgBox "Store " & Store.Name & " is owned by " & Store.Owner.Name 
    End If 
    next 
相關問題