【发布时间】:2018-01-25 18:29:22
【问题描述】:
我们开发了一个 C# Office VSTO 加载项,它与正在运行的 Outlook 实例通信(或启动一个新实例),并且在尝试创建 Outlook 任务或约会...
异常信息如下:
操作中止(HRESULT 异常:0x80004004 (E_ABORT))
这发生在这里:
Outlook.Account DefaultAccount = null;
Outlook.Application outlookApp = GetOutlookApp(); //returns Application object of running Outlook instance / creates a new instance - it works for them.
DefaultAccount = GetAccountForFolder(outlookApp); //returns the default account of the user. Tried it with a simple setup, only one account etc. - it works for them
String defaultemailaddress;
//CODE RUNS UNTIL THIS POINT
if (DefaultAccount == null) //if somehow this would end up NULL, which is not the case, because: see code snippet below!
{
defaultemailaddress = outlookApp.Session.CurrentUser.AddressEntry.Address;
}
else
{
defaultemailaddress = DefaultAccount.SmtpAddress; //this could be the problem, but I can't debug it further, and it works in the code block below, to get the AccountType, so I don't understand why I couldn't get the SmtpAddress without a hard exception
}
//FAILS BEFORE THIS LINE COULD RUN.
String email = "test@emailserver.com";
在与用户联系后,他们告诉我们,他们在非常有限的权限集和网络下运行。
奇怪的是,这段 sn-p 代码实际上对他们来说运行流畅,这证明 Outlook 和其他 Office 加载项之间的连接正常:
Outlook.Application oApp = GetOutlookApp();
Outlook.Account DefaultAccount = GetAccountForFolder(oApp);
String AccountType = DefaultAccount.AccountType.ToString();
IT 部门已尝试在受影响的 PC 上调整 Outlook 的安全策略。他们允许编程访问。
他们无法以管理员权限启动这些工具,但这不是必需的。最后 3 行代码工作(获取帐户类型)的事实证明应用程序确实正确启动,但看起来它只能运行某些功能......
我还想指出,他们正在使用 Exchange,但显然他们没有同步问题(如果这些可能会影响任何事情的话……)
编辑: 下面是 GetAccountForFolder 的实现,它获取默认的 Outlook.Account 对象。这是我发现的一个代码 sn-p,发现它工作得很好。
public static Outlook.Account GetAccountForFolder(Outlook.Application outlookApp)
{
// Obtain the store on which the folder resides.
Outlook.Store store = outlookApp.Session.DefaultStore;
// Enumerate the accounts defined for the session.
foreach (Outlook.Account account in outlookApp.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;
}
【问题讨论】:
-
GetAccountForFolder 的实现是什么?你在 OutlookSpy 中使用同样的问题吗? (单击 Namespace 按钮,选择 Accounts,单击 Browse,转到 IEnumVariant 选项卡,双击相关帐户)。
-
嗨,德米特里!感谢您围绕任何与 Outlook 相关的积极工作,我发现您的许多 cmets/answers 很有帮助!你的意思是我应该要求用户安装 OutlookSpy 并将其用于本次调查?
标签: c# outlook vsto outlook-addin office-addins