通过 Mail.EntryID 从 C# 在 Outlook 中打开特定的 MailItem

Open Specific MailItem in Outlook from C# via Mail.EntryID

类似这个问题, Open Specific MailItem in Outlook from C# ,在 C# VSTO 应用程序中,我正在尝试使用方法 GetFolderFromID 在新的 outlook window/inspector 中打开一封电子邮件并将其传递给 EntryIDStoreID

完整代码如下:

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 中选择了电子邮件后,以下代码才会在新 window 中打开请求的电子邮件。

getItem.Display();

如果没有选择,下面的错误returns。

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

我也曾尝试通过它添加一个新的检查器和 activating/displaying 电子邮件对象,但没有成功。

亲切的问候

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