Outlook加载项如何检测何时删除帐户

问题描述 投票:0回答:1

我从如下所示的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);
    }

但是,Outlook返回的帐户,包括已删除的帐户。删除帐户后似乎没有发生任何事件。

删除帐户后,是否可以获取除已删除帐户之外的其他帐户?如何获得除已删除帐户之外的帐户?

c# outlook outlook-addin
1个回答
0
投票

Outlook对象模型不为此提供任何事件。最好的办法是处理将要以编程方式或通过用户操作从当前会话中删除Stores.BeforeStoreRemove时触发的Store事件。这是MSDN对活动说的话:


Outlook必须正在运行才能触发此事件。发生以下任何情况时都会触发此事件:

  • [用户通过单击快捷菜单上的Close命令来删除商店。

  • [通过调用Namespace.RemoveStore以编程方式删除商店。

发生以下任何情况,均不会触发此事件:

  • Outlook关闭并关闭主存储或委托存储时。

  • 如果通过Microsoft Windows“控制面板”中的“邮件”小程序删除了存储,并且Outlook未运行。

  • 在Microsoft Exchange Server对话框的“高级”选项卡上删除了一个委托存储。

  • 未运行Outlook时,通过“帐户管理器”对话框的“数据文件”选项卡删除了存储。

  • IMAP存储已从配置文件中删除。

您可以使用此事件来确定存储已被删除,如果您的应用程序需要存储(例如重新安装存储),则可以采取适当的措施。否则,您将不得不轮询商店集合。

© www.soinside.com 2019 - 2024. All rights reserved.