获取 Outlook 2007 邮件内容时出错
我目前正在制作一个程序,需要分析outlook 2007和outlook 2010中的邮件消息。
在安装了office套件的机器上,它工作没有问题。如果他们只有 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;
I'm currently making a program that needs to analyze the mail message in outlook 2007 and outlook 2010.
On machines that have the office suite installed, it works no problem. If they only have outlook, it doesn't seem to be able to get the mail message and when I try to get the content of the document, it gives me the following error:
"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))."
This is the code I'm using to get the message:
Office.Word.Document document = inspector.WordEditor as Office.Word.Document;
string body = document.Content.Text;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我所知,您应该将其投射到 如果您要查看邮件,则 MailItem 不是 Word 文档。 MailItem 对象有一个名为 Body (以及关联的 BodyFormat )。
另外,@StackOverflowException是正确的,在开始操作它之前始终检查该项目是否不为空。这将告诉您它是否是您认为的类型。
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.