Outlook 插件如何检测帐户何时被删除
How can Outlook addin detect when an account is removed
我从 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 return 帐户,包括已删除的帐户。
删除账号时似乎没有发生任何事件。
账号被移除后,有办法获取除被移除账号之外的账号吗?我如何才能获得不包括已删除帐户的帐户?
Outlook 对象模型不为此提供任何事件。您可以做的最好的事情是处理 Stores.BeforeStoreRemove 事件,该事件在 Store
即将以编程方式或通过用户操作从当前会话中删除时触发。以下是 MSDN 对事件的描述:
Outlook 必须 运行 才能触发此事件。发生以下任一情况时将触发此事件:
用户单击快捷菜单上的 Close
命令删除了商店。
通过调用 Namespace.RemoveStore
.
以编程方式删除商店
当发生以下任一情况时,不会触发此事件:
当 Outlook 关闭并关闭主存储或委托存储时。
如果商店是通过 Microsoft Windows 控制面板中的邮件小程序删除的,而 Outlook 不是 运行。
在 Microsoft Exchange Server 对话框的“高级”选项卡上删除了委托存储。
当 Outlook 不是 运行.
时,通过“帐户管理器”对话框的“数据文件”选项卡删除存储
IMAP 商店已从配置文件中删除。
您可以使用此事件来确定存储已被删除,并在您的应用程序需要该存储时采取适当的操作(例如重新安装存储)。否则,您将不得不求助于轮询 Stores 集合。
在 MAPI 级别(C++ 或 Delphi),帐户事件是通过 IOlkAccountManager::Advise method. You can see the events fire in OutlookSpy 实现的(我是它的作者 - 单击 IOlkAccountManager 按钮,转到“建议”选项卡。
Outlook 对象模型不公开这些事件。如果使用 Redemption (I am also its author) is an option, it exposes all account events through the RDOAccounts 对象 - AccountChange, AccountAdd, AccountRemove, AccountBeforeRemove, AccountOrderChange
.
我从 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 return 帐户,包括已删除的帐户。
删除账号时似乎没有发生任何事件。
账号被移除后,有办法获取除被移除账号之外的账号吗?我如何才能获得不包括已删除帐户的帐户?
Outlook 对象模型不为此提供任何事件。您可以做的最好的事情是处理 Stores.BeforeStoreRemove 事件,该事件在 Store
即将以编程方式或通过用户操作从当前会话中删除时触发。以下是 MSDN 对事件的描述:
Outlook 必须 运行 才能触发此事件。发生以下任一情况时将触发此事件:
用户单击快捷菜单上的
Close
命令删除了商店。通过调用
Namespace.RemoveStore
. 以编程方式删除商店
当发生以下任一情况时,不会触发此事件:
当 Outlook 关闭并关闭主存储或委托存储时。
如果商店是通过 Microsoft Windows 控制面板中的邮件小程序删除的,而 Outlook 不是 运行。
在 Microsoft Exchange Server 对话框的“高级”选项卡上删除了委托存储。
当 Outlook 不是 运行.
时,通过“帐户管理器”对话框的“数据文件”选项卡删除存储
IMAP 商店已从配置文件中删除。
您可以使用此事件来确定存储已被删除,并在您的应用程序需要该存储时采取适当的操作(例如重新安装存储)。否则,您将不得不求助于轮询 Stores 集合。
在 MAPI 级别(C++ 或 Delphi),帐户事件是通过 IOlkAccountManager::Advise method. You can see the events fire in OutlookSpy 实现的(我是它的作者 - 单击 IOlkAccountManager 按钮,转到“建议”选项卡。
Outlook 对象模型不公开这些事件。如果使用 Redemption (I am also its author) is an option, it exposes all account events through the RDOAccounts 对象 - AccountChange, AccountAdd, AccountRemove, AccountBeforeRemove, AccountOrderChange
.