获取outlook 2007消息的内容时出错

时间:2011-02-21 20:32:18

标签: c# .net outlook-2007-addin

我目前正在制作一个程序,需要分析Outlook 2007和outlook 2010中的邮件消息。

在安装了办公套件的机器上,它没有问题。如果他们只有Outlook,它似乎无法获取邮件消息,当我尝试获取文档的内容时,它会给我以下错误:

"Unable to cast COM object of type 
'Microsoft.Office.Interop.Word.DocumentClass' to interface type
'Microsoft.Office.Interop.Word._Document'. This operation failed because the 
QueryInterface call on the COM component for the interface with IID '{0002096B-0000-
0000-C000-000000000046}' failed due to the following error: No such interface supported    
(Exception from HRESULT: 0x80004002 (E_NOINTERFACE))."

这是我用来获取消息的代码:

Office.Word.Document document = inspector.WordEditor as Office.Word.Document;
string body = document.Content.Text;

1 个答案:

答案 0 :(得分:1)

据我所知,如果你要追踪这条消息,你应该将它投射到MailItem而不是word文档。关闭MailItem对象的是名为Body的属性(以及关联的BodyFormat)。

此外,@ StackOverflowException是正确的,在开始操作之前,请始终检查该项是否为null。这将告诉您它是否是您认为的类型。