【问题标题】:Error getting the content of an outlook 2007 message获取 Outlook 2007 消息的内容时出错
【发布时间】:2011-07-01 13:17:18
【问题描述】:

我目前正在制作一个程序,需要在 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;

【问题讨论】:

  • 为了避免异常,当然你应该在获取document.Content.Text之前做if(document != null)检查。而且,我认为您将无法在没有安装 Word 的情况下使用 MS Word 对象库;因此是空引用。

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


【解决方案1】:

据我所知,如果您要查找消息,则应该将其转换为 MailItem 而不是 word 文档。 MailItem 对象之外是一个名为Body 的属性(以及一个关联的BodyFormat)。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-10-08
    • 1970-01-01
    • 2021-01-28
    • 2013-04-02
    • 2016-11-15
    • 2023-04-05
    • 2014-11-24
    相关资源
    最近更新 更多