简体   繁体   English

VSTO - 如何从 Outlook.Store 实体获取帐户 email 地址

[英]VSTO - How get account email address from Outlook.Store entity

Some time ago to get Outlook accounts and account info (eg Email address, SMTP address) i was use Outlook.Accounts entity, but Outlook.Accounts caches data and doesn't support events like Add/Remove. Some time ago to get Outlook accounts and account info (eg Email address, SMTP address) i was use Outlook.Accounts entity, but Outlook.Accounts caches data and doesn't support events like Add/Remove. Here I was offered to switch to Outlook.Stores ( Outlook.Store ) entity, but I don't understand how I can get the Email address from Outlook.Store at least. Here I was offered to switch to Outlook.Stores ( Outlook.Store ) entity, but I don't understand how I can get the Email address from Outlook.Store at least.

Generally, stores do not have an intrinsic identity - imagine a standalone PST store: there is no user identity.通常,商店没有内在身份——想象一个独立的 PST 商店:没有用户身份。 Or you can have multiple POP3/SMTP accounts delivering to the same PST store - you now have multiple identities associated with the store.或者,您可以将多个 POP3/SMTP 帐户传送到同一个 PST 商店 - 您现在有多个与该商店关联的身份。

Or imagine having a PF store - it is accessible to multiple users without having its own identity.或者想象一下拥有一个 PF 商店 - 多个用户可以访问它,而无需拥有自己的身份。

Only Exchange stores have a notion of an owner.只有 Exchange 商店才有所有者的概念。 You can go from an Exchange store to an email account by looping through the Namespace.Accounts collection and comparing (using Namespace.CompareEntryIDs ) the entry id of your store in question and the store exposed by the Account.DeliveryStore property.您可以通过循环访问Namespace.Accounts集合并比较(使用Namespace.CompareEntryIDs )相关商店的条目 id 和Account.DeliveryStore属性公开的商店,从 Exchange 商店 go 到 email 帐户。

If using Redemption is an option (I am its author), it exposes the Exchange mailbox owner directly through the RDOExchangeMailboxStore .如果使用Redemption是一个选项(我是它的作者),它会直接通过RDOExchangeMailboxStore公开 Exchange 邮箱所有者。 Owner property (returns RDOAddressEntry object). Owner属性(返回RDOAddressEntry对象)。

If the store is associated with any account configured in Outlook you can use the following code which iterates over all accounts configured and finds the required one where you may ask for an email address:如果商店与 Outlook 中配置的任何帐户相关联,您可以使用以下代码遍历所有配置的帐户并找到所需的帐户,您可以在其中要求 email 地址:

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

The Account.SmtpAddress property returns a string representing the Simple Mail Transfer Protocol (SMTP) address for the Account . Account.SmtpAddress属性返回一个字符串,该字符串表示Account的简单邮件传输协议 (SMTP) 地址。 The purpose of SmtpAddress and Account.UserName is to provide an account-based context to determine identity. SmtpAddressAccount.UserName的目的是提供基于帐户的上下文来确定身份。 If the account does not have an SMTP address, SmtpAddress returns an empty string.如果账户没有 SMTP 地址, SmtpAddress返回一个空字符串。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM