VSTO outlook加载项如何从Outlook通讯组列表中检索Exchange通讯组列表成员

时间:2011-06-13 10:38:26

标签: vsto outlook-addin distribution-list

我有VSTO加载项,它从mailitem获取收件人并将其保存在我们的用户列表中。 如果交换分发列表或交换联系人作为收件人,它通过从这两者中提取smtp邮件地址工作正常。为此,outlook对象模型可以工作。

但是,当将Exchange分发列表添加为Outlook通讯组列表中的成员并将邮件发送到此本地通讯组列表时,会出现问题。有没有办法从这个嵌套的通讯组列表中提取每个联系人的smtp地址。

到目前为止,我有用户DistListItem.GetMember(i)获取此通讯组列表成员的方法。它提供了一个Recipient对象,当我尝试从该对象访问属性member.AddressEntry.AddressEntryUserType时,它会抛出异常“找不到该项”。 有谁知道如何从这个收件人对象获得分发列表成员类型或entryId?

1 个答案:

答案 0 :(得分: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);
                }
        }
    }
}