2011-06-13 87 views
1

我有VSTO加載項,它從mailitem獲取收件人並將其保存在我們的用戶列表中。 在作爲收件人的交換分發列表或交換聯繫人的情況下,它可以通過從這兩個郵件地址中提取smtp郵件地址而正常工作。爲此,Outlook對象模型起作用。VSTO outlook加載項如何從Outlook通訊組列表中檢索Exchange通訊組列表

但是當Exchange分發列表作爲Outlook分發列表中的成員添加並且郵件發送到此本地分發列表時,會出現問題。有沒有什麼辦法從這個嵌套的分發列表中提取每個聯繫人的smtp地址。

到目前爲止,我有用戶DistListItem.GetMember(i)獲取此通訊組列表成員的方法。它提供了一個Recipient對象,當我嘗試從這個對象訪問一個屬性member.AddressEntry.AddressEntryUserType時,它會拋出一個異常「The item could not be found」。 有誰知道我如何從這個收件人對象獲取通訊組列表成員類型或entryId?

回答

0
private void GetDistributionListMembers() 
{ 
    Outlook.SelectNamesDialog snd = 
     Application.Session.GetSelectNamesDialog(); 
    Outlook.AddressLists addrLists = 
     Application.Session.AddressLists; 
    foreach (Outlook.AddressList addrList in addrLists) 
    { 
     if (addrList.Name == "All Groups") 
     { 
      snd.InitialAddressList = addrList; 
      break; 
     } 
    } 
    snd.NumberOfRecipientSelectors = 
     Outlook.OlRecipientSelectors.olShowTo; 
    snd.ToLabel = "D/L"; 
    snd.ShowOnlyInitialAddressList = true; 
    snd.AllowMultipleSelection = false; 
    snd.Display(); 
    if (snd.Recipients.Count > 0) 
    { 
     Outlook.AddressEntry addrEntry = 
      snd.Recipients[1].AddressEntry; 
     if (addrEntry.AddressEntryUserType == 
      Outlook.OlAddressEntryUserType. 
      olExchangeDistributionListAddressEntry) 
     { 
      Outlook.ExchangeDistributionList exchDL = 
       addrEntry.GetExchangeDistributionList(); 
      Outlook.AddressEntries addrEntries = 
       exchDL.GetExchangeDistributionListMembers(); 
      if (addrEntries != null) 
       foreach (Outlook.AddressEntry exchDLMember 
        in addrEntries) 
       { 
        Debug.WriteLine(exchDLMember.Name); 
       } 
     } 
    } 
} 
相關問題