VSTO-如何从Outlook.Store实体获取帐户电子邮件地址



一段时间前,为了获取Outlook帐户和帐户信息(例如电子邮件地址、SMTP地址(,我使用了Outlook.Accounts实体,但Outlook.Accounts缓存数据,不支持Add/Remove等事件。在这里,我被提供切换到Outlook.Stores(Outlook.Store(实体,但我不明白如何从Outlook.Store获得电子邮件地址。

如果商店与Outlook中配置的任何帐户关联,您可以使用以下代码,该代码会迭代所有配置的帐户,并找到所需的帐户,您可以在其中要求提供电子邮件地址:

Outlook.Account GetAccountForFolder(Outlook.Folder folder)
{
// Obtain the store on which the folder resides.
Outlook.Store store = folder.Store;
// Enumerate the accounts defined for the session.
foreach (Outlook.Account account in Application.Session.Accounts)
{
// Match the DefaultStore.StoreID of the account
// with the Store.StoreID for the currect folder.
if (account.DeliveryStore.StoreID  == store.StoreID)
{
// Return the account whose default delivery store
// matches the store of the given folder.
return account;
}
}
// No account matches, so return null.
return null;
}

Account.SmtpAddress属性返回一个字符串,表示Account的简单邮件传输协议(SMTP(地址。SmtpAddressAccount.UserName的目的是提供基于帐户的上下文来确定身份。如果帐户没有SMTP地址,SmtpAddress将返回一个空字符串。

通常,存储没有内部标识-想象一个独立的PST存储:没有与之关联的用户标识。或者,您可以有多个POP3/SMTP帐户传递到同一个PST存储-您现在有多个与PST存储关联的标识。

或者想象一下有一个PF商店——它可以由多个用户访问,而不需要自己的身份。

只有Exchange商店才有所有者的概念。您可以通过循环使用Namespace.Accounts集合并比较(使用Namespace.CompareEntryIDs(有问题的存储的条目id和Account.DeliveryStore属性公开的存储,从Exchange存储转到电子邮件帐户。

如果可以选择使用Redemption(我是它的作者(,它将直接通过RDOExchangeMailboxStore公开Exchange邮箱所有者。Owner属性(返回RDOAddressEntry对象(。

最新更新