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

问题描述 投票:0回答:1

类似于这个问题, Open Specific MailItem in Outlook from C#,在 C# VSTO 应用程序中,我尝试使用方法 GetFolderFromID 在新的 outlook 窗口/检查器中打开电子邮件,并传递它的 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 中已选择电子邮件时才在新窗口中打开请求的电子邮件。

getItem.Display();

如果没有选择,返回以下错误。

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

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

亲切的问候

c# outlook vsto
1个回答
1
投票

错误仅表示对话框已打开。确保没有显示 modal 窗口,并确保您永远不会调用

MailItem.Display(true
) 以模态方式显示项目。

© www.soinside.com 2019 - 2024. All rights reserved.