【问题标题】:How to get the sender e-mail address associated by the folder item? (vsto / outlook 2010 / mapi)如何获取文件夹项关联的发件人电子邮件地址? (vsto / 展望 2010 / mapi)
【发布时间】:2016-05-25 04:33:47
【问题描述】:

我的 Outlook 2010-Add-In (c#) 中有许多文件夹。它们在我的私人邮箱或我的一个共享邮箱中。

现在我正在寻找一种解决方案来了解如何获取与专用文件夹关联的正确电子邮件地址(发件人/收件人)。它可以是我私人邮箱中的任何文件夹,也可以是我共享邮箱中的任何文件夹。

我想,也许我可以使用文件夹项中的 EntryId / StoreId 来识别相应的电子邮件地址。

我已经知道,我可以从任何邮件项目中获取电子邮件地址,但我不是在寻找这个解决方案。

【问题讨论】:

  • 您的意思是要找出父 Exchange 邮箱的所有者?
  • 是的,我就是这个意思。

标签: c# vsto outlook-addin outlook-2010 mapi


【解决方案1】:

我喜欢回答我自己的问题:我认为我找到了一个可行的解决方案。

我不处理函数内部的任何异常,我从外部处理。

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;
            }
        }
    }

【讨论】:

  • PR_MAILBOX_OWNER_ENTRYID 仅在在线模式下可用。缓存模式不会暴露它。
  • 感谢您的注意,我们不使用缓存模式。
【解决方案2】:

你可以试试

  1. 使用 Store.PropertyAccessor.GetProperty 从商店中检索 PR_MAILBOX_OWNER_ENTRYID 属性,但仅在线商店公开,缓存商店不公开。

  2. 解析 Exchange 商店条目 ID 以提取商店所有者的 DN,然后创建 GAL 用户条目 ID。

  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

【讨论】:

    猜你喜欢
    • 2021-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-11
    • 2011-11-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多