【发布时间】:2016-06-02 18:51:49
【问题描述】:
我们使用 Add-in-Express 编写了一个 Outlook 插件。代码:
private void CreateShowMessageUsingCreateItem(Outlook._Application OutlookApp)
{
Outlook.MailItem mail = null;
try
{
mail = OutlookApp.CreateItem(Outlook.OlItemType.olMailItem) as Outlook.MailItem;
mail.Save();
mail.Display(false);
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
}
finally
{
if (mail != null) Marshal.ReleaseComObject(mail);
}
}
当 Outlook 连接到 Exchange 时有效。失败时 Outlook 已连接到 Office365。错误:
Exception: System.Runtime.InteropServices.COMException (0x80004005): The operation failed.
at Microsoft.Office.Interop.Outlook.ApplicationClass.CreateItem(OlItemType ItemType)
at DocuSignInk.DSToolbox.ShowResponse(MailItem senderEmail) in C:\docusign_source\Ink_Outlook\DocuSignInk\DSToolbox.cs:line 540
一些研究表明你需要释放你的对象 在循环中进行这些调用时。但我不在一个循环中。我 连一个上班的电话都打不通,所以我没说到点子上 我可以释放任何东西。
使用 Wireshark 和 Charles 进行测试表明问题出在 在客户端。我想看看有没有更详细的 来自服务器的错误,但没有到服务器的流量 完全没有。
一个快速的 Python 脚本可以从命令行运行。
import win32com.client
outlook = win32com.client.Dispatch('Outlook.Application')
mail = outlook.CreateItem(win32com.client.constants.olMailItem)
mail.Save()
mail.Display(False)
所以它一定是客户端的东西。我猜可能与线程有关?
【问题讨论】: