1

我目前正在制作一个需要分析 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;
4

1 回答 1

1

To my knowledge, you should be casting it to a MailItem not a word document if you're going after the message. Off the MailItem object is a property called Body (and an associated BodyFormat).

Also, @StackOverflowException is correct, always check if the item is not null before you begin to manipulate it. This will tell you if it is or isn't the type you think it is.

于 2011-02-22T14:41:46.527 回答