Outlook Interop电子邮件-2个邮件项问题

问题描述

在我的winforms应用程序(VB网络)中,我需要使用Interop打开Outlook应用程序,并打开包含一些预填充数据(如主题)的mailitem。认情况下,AIP(Azure信息保护)认为以前的电子邮件分类设置。为了解决这个问题,在显示实际电子邮件之前,我先打开和关闭一个邮件项。

这是第一个变体-出现错误RPC服务器不可用。 (来自HRESULT的异常:0x800706BA)

Dim oAppt As Microsoft.Office.Interop.outlook.application = New Microsoft.Office.Interop.outlook.application()
'Fix for the email classification issue
Dim nMail As Microsoft.Office.Interop.Outlook.MailItem = oAppt.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem)
nMail.Subject = "---"
nMail.display(False)
nMail.Close(Microsoft.Office.Interop.Outlook.OlInspectorClose.oldiscard)    

if nMail IsNot nothing Then
    System.Runtime.InteropServices.Marshal.ReleaseComObject(nMail)
End If  

Dim newMail = oAppt.CreateItem(OlItemType.olMailItem) <--Fails Here with The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
newMail.Subject = emailSubject
newMail.To = emailTo
newMail.CC = emailCc

...

一个变体...实例化另一个Outlook应用程序-失败,并显示InvalidCastException:无法将类型为“ Microsoft.Office.Interop.outlook.applicationClass”的COM对象转换为接口类型为“ Microsoft.Office.Interop.Outlook._Application”。由于以下错误,此操作失败是因为在COM组件上针对IID为“ {00063001-0000-0000-C000-000000000046}”的接口的COM组件上的QueryInterface调用由于以下错误而失败:RPC服务器不可用。 (来自HRESULT的异常:0x800706BA)。

Dim oAppt1 As Microsoft.Office.Interop.outlook.application = New Microsoft.Office.Interop.outlook.application()
'Fix for the email classification issue
Dim nMail As Microsoft.Office.Interop.Outlook.MailItem = oAppt1.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem)
nMail.Subject = "---"
nMail.display(False)
nMail.Close(Microsoft.Office.Interop.Outlook.OlInspectorClose.oldiscard)    

if nMail IsNot nothing Then
    System.Runtime.InteropServices.Marshal.ReleaseComObject(nMail)
End If  
If oAppt1 IsNot nothing Then
   System.Runtime.InteropServices.Marshal.ReleaseComObject(oAppt1)
End If

Dim oAppt2 As Microsoft.Office.Interop.outlook.application = New Microsoft.Office.Interop.outlook.application() <-- fails here

Dim newMail = oAppt2.CreateItem(OlItemType.olMailItem)
newMail.Subject = emailSubject
newMail.To = emailTo
newMail.CC = emailCc

....

要注意的另一件事是,如果Outlook App正在运行,则两个变体都可以正常运行。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)