当我在控制台应用程序中执行以下代码时,它会给出准确的结果,但是当我在 Windows 窗体中尝试它时,它会在 Outlook.Application app = new Outlook.Application(); 上引发 COM 异常;
异常是“由于以下错误,检索具有 CLSID {0006F03A-0000-0000-C000-000000000046} 的组件的 COM 类工厂失败:80080005 服务器执行失败(来自 HRESULT 的异常:0x80080005 (CO_E_SERVER_EXEC_FAILURE))。”
if (comboBoxFolder.SelectedIndex == 0)
{
setInboxView();
Outlook.Application app = new Outlook.Application();
Outlook.NameSpace outlookNs = app.GetNamespace("MAPI");
Outlook.MAPIFolder emailFolder = outlookNs.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);
foreach (Outlook.MailItem item in emailFolder.Items)
{
mails[0] = item.SenderEmailAddress;
mails[1] = item.To;
mails[2] = item.Subject;
mails[3] = Convert.ToString(item.ReceivedTime);
}