由于 outlook 界面无法打开 mailItem..!

Unable to open mailItem because of outlook interface..!

我有一个应用程序,我在其中使用 Outlook 互操作创建了一个 mailItem。 在某些系统上,代码可以正常工作。

但在其中一个系统上出现此错误:

Message= Unable to cast COM object of type 'Microsoft.Office.Interop.Outlook.ApplicationClass' to interface type 'Microsoft.Office.Interop.Outlook._Application'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{00063001-0000-0000-C000-000000000046}' failed

due to the following error: Interface not registered

我觉得跟寄存器有关系看:Answer on Error accesing COM components

但是我需要在代码中解决这个问题,因为我无法访问所有存在此类问题的系统。

using Outlook = Microsoft.Office.Interop.Outlook;

//Create email body with the customers
string mailBody = customers;
//Create the email with the settings
Outlook.Application outlookApp = new Outlook.Application();
Outlook.MailItem mailItem = (Outlook.MailItem)outlookApp.CreateItem(Outlook.OlItemType.olMailItem);
mailItem.Subject = mailSubject;
mailItem.Attachments.Add(totalPath);
mailItem.Body = mailBody;
mailItem.Importance = Outlook.OlImportance.olImportanceNormal;
try
{
    //Try to open outlook, set message if its not possible to open outlook
    mailItem.Display(true);
}
catch (Exception ex)
{
    MessageBox.Show(ex.Message);
    return false;
}

如何在我的代码中解决这个问题?

P.S。每个系统都用office 2013版!

尝试改用以下代码:

 oApp = Activator.CreateInstance(Type.GetTypeFromProgID("Outlook.Application")) as Microsoft.Office.Interop.Outlook.Application;

windows 注册表记录似乎有问题。查看类似的论坛主题 - Error: Unable to cast COM object of type 'Microsoft.Office.Interop.Outlook.ApplicationClass' to interface type 'Microsoft.Office.Interop.Outlook._Application'.

您的PC上是否安装了Office的Click2Run版?有关详细信息,请参阅 How to: Verify Whether Outlook Is a Click-to-Run Application on a Computer