【问题标题】:Open Specific MailItem in Outlook from C# via Mail.EntryID通过 Mail.EntryID 从 C# 在 Outlook 中打开特定的 MailItem
【发布时间】:2018-03-25 04:40:45
【问题描述】:

与这个问题类似, Open Specific MailItem in Outlook from C# ,在 C# VSTO 应用程序中,我尝试使用 GetFolderFromID 方法在新的 Outlook 窗口/检查器中打开电子邮件,并传递 EntryID商店 ID

完整代码如下:

Outlook.Application myApp = new Outlook.ApplicationClass();
Outlook.NameSpace mapiNameSpace = myApp.GetNamespace("MAPI");
Outlook.MAPIFolder mySentBox = mapiNameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSentMail);                
Outlook.MailItem myMail = ((Outlook.MailItem)mySentBox.Items[1]);
string guid = myMail.EntryID;
string folderStoreID = mySentBox.StoreID;
Outlook.MailItem getItem = (Outlook.MailItem)mapiNameSpace.GetItemFromID(guid, folderStoreID);
getItem.Display();

只有在 Outlook 中已选择电子邮件时,以下代码才会在新窗口中打开请求的电子邮件。

getItem.Display();

如果不选择,则返回以下错误。

System.Runtime.InteropServices.ComException: 'A dialog box is open. Close it and try again'.

我还尝试添加一个新的检查器并通过它激活/显示电子邮件对象,但没有成功。

亲切的问候

【问题讨论】:

    标签: c# outlook vsto


    【解决方案1】:

    该错误仅表示打开了一个对话框。确保没有显示模态窗口,并确保您曾经调用 MailItem.Display(true) 以模态显示项目。

    【讨论】:

    • 嗨,Dimitry,似乎我没有调用现有的 Outlook.Application,而是创建了一个新的,然后导致了模态问题。
    • Outlook 是一个单例 - 您不能在同一 Windows 用户上下文中启动多个 Outlook.exe 实例。
    猜你喜欢
    • 2012-12-05
    • 2011-04-10
    • 2015-08-30
    • 2014-08-28
    • 1970-01-01
    • 2023-03-06
    • 2015-12-11
    • 2014-10-12
    • 2015-04-29
    相关资源
    最近更新 更多