简体   繁体   English

Outlook插件如何检测帐户何时被删除

[英]How can Outlook addin detect when an account is removed

I get accounts from Outlook like below.我从 Outlook 获得帐户,如下所示。

    Outlook.NameSpace ns = null;
    Outlook.Accounts accounts = null;
    Outlook.Account account = null;
    string accountList = string.Empty;

    try
    {
        ns = OutlookApp.Session;
        accounts = ns.Accounts;
        for (int i = 1; i <= accounts.Count; i++)
        {
            account = accounts[i];
            accountList += String.Format("{0} - {1}{2}", 
                account.UserName,  
                account.SmtpAddress, 
                Environment.NewLine);
            if (account != null)
                Marshal.ReleaseComObject(account);
        }
        MessageBox.Show(accountList);
    }
    finally
    {
        if (accounts != null)
            Marshal.ReleaseComObject(accounts);
        if (ns != null)
            Marshal.ReleaseComObject(ns);
    }

However, Outlook return accounts, including those that have been removed.但是,Outlook 会返回帐户,包括已删除的帐户。
It seems that there are no events that occur when the account is removed.删除帐户时似乎没有发生任何事件。

After the account is removed, is there a way to get the accounts excluding the removed account?账户被移除后,有没有办法获取被移除账户以外的账户? How I can get accounts excluding removed account?如何获取不包括已删除帐户的帐户?

The Outlook object model doesn't provide any event for that. Outlook object model 没有为此提供任何事件。 The best what you can do is to handle the Stores.BeforeStoreRemove event which is fired when a Store is about to be removed from the current session either programmatically or through user action.您可以做的最好的事情是处理Stores.BeforeStoreRemove事件,该事件在即将从当前Store中以编程方式或通过用户操作删除时触发。 Here is what MSDN says for the event:以下是 MSDN 对该事件的说明:


Outlook must be running in order for this event to fire. Outlook 必须运行才能触发此事件。 This event will fire when any of the following occurs:当发生以下任何情况时,将触发此事件:

  • A store is removed by the user clicking the Close command on the Shortcut menu.用户通过单击快捷菜单上的Close命令来删除商店。

  • A store is removed programmatically by calling Namespace.RemoveStore .通过调用Namespace.RemoveStore以编程方式删除存储。

This event will not fire when any of the following occurs:当发生以下任何情况时,此事件不会触发:

  • When Outlook shuts down and closes a primary or delegate store.当 Outlook 关闭并关闭主存储或委托存储时。

  • If a store is removed through the Mail applet in the Microsoft Windows Control Panel and Outlook is not running.如果通过 Microsoft Windows 控制面板中的邮件小程序删除了商店,并且 Outlook 未运行。

  • A delegate store is removed on the Advanced tab of the Microsoft Exchange Server dialog box. Microsoft Exchange Server 对话框的高级选项卡上删除了委托存储。

  • A store is removed through the Data Files tab of the Account Manager dialog box when Outlook is not running.当 Outlook 未运行时,将通过帐户管理器对话框的数据文件选项卡删除存储。

  • An IMAP Store is removed from the profile.从配置文件中删除 IMAP 存储。

You can use this event to determine that a store has been removed, and take appropriate actions if the store is required for your application (such as remounting the store).您可以使用此事件来确定商店已被删除,并在您的应用程序需要该商店时采取适当的措施(例如重新安装该商店)。 Otherwise you would have to resort to polling the Stores collection.否则,您将不得不求助于轮询 Stores 集合。

On the MAPI level (C++ or Delphi), account events are implemented through IOlkAccountManager::Advise method.在 MAPI 级别(C++ 或 Delphi),帐户事件是通过IOlkAccountManager::Advise方法实现的。 You can see the events fire in OutlookSpy (click IOlkAccountManager button, go to the Advise tab).您可以在OutlookSpy中看到事件触发(单击 IOlkAccountManager 按钮,go 到 Advise 选项卡)。

Outlook Object Model does not expose these events. Outlook Object Model 不公开这些事件。 If using Redemption is an option, it exposes all account events through the RDOAccounts object - AccountChange, AccountAdd, AccountRemove, AccountBeforeRemove, AccountOrderChange .如果使用Redemption是一个选项,它会通过RDOAccounts object - AccountChange, AccountAdd, AccountRemove, AccountBeforeRemove, AccountOrderChange公开所有帐户事件。

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

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