使用Outlook API打开电子邮件时引发错误 [英] Error thrown when opening e-mails using outlook api

查看:249
本文介绍了使用Outlook API打开电子邮件时引发错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题::使用Outlook API打开电子邮件似乎有效的.MSG文件时,我收到以下错误消息:

Question: I get the following error message when opening what appear to be valid .MSG files using Outlook API to open emails:

无法转换类型为COM的对象 'System .__ ComObject'到接口类型 "Microsoft.Office.Interop.Outlook.MailItem". 该操作失败,因为 COM上的QueryInterface调用 具有IID的接口的组件 '{00063034-0000-0000-C000-000000000046}' 由于以下错误而失败:否 支持这样的接口(异常 从HRESULT:0x80004002 (E_NOINTERFACE).

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

MSG文件可以在Outlook中正常打开,我可以保证这些表单是标准的Outlook邮件表单.

The MSG files open fine in outlook and I'm assured that the forms are standard outlook mail forms.

此错误最可能的原因是什么?

What is the most likely cause of this error?


背景:我的一位同事从交易所中导出了大量邮箱作为PST,然后针对PST文件运行工具以生成类似于原始邮箱的文件结构,该邮箱填充了.MSG文件.例如:

Background: One of my colleagues has exported a large number of mailboxes from exchange as PSTs and then run a tool against the PST files to produce a file-structure resembling the original mailbox filled with .MSG files. For example:

\ USERNAME
\ USERNAME \ INBOX
\ USERNAME \ SENT
\ USERNAME \ DRAFTS
\ USERNAME \ DELETED

\USERNAME
\USERNAME\INBOX
\USERNAME\SENT
\USERNAME\DRAFTS
\USERNAME\DELETED

然后我在这些文件夹中扫描.MSG文件,并尝试使用Outlook API打开它们.

I then scan these folders for .MSG files and attempt to open them using Outlook API.

Outlook.Application app = new Microsoft.Office.Interop.Outlook.Application();

Outlook.NameSpace ns = app.GetNamespace("MAPI");

Outlook.MailItem item = (Outlook.MailItem)ns.OpenSharedItem(EmailPath);

Subject = item.Subject;

推荐答案

OOM中的所有* Item对象都实现Type属性.使用反射动态获取该属性,而不是将返回的对象强制转换为MailItem.

All *Item objects in OOM implement the Type property. Retrieve that property dynamically using reflection instead of casting the returned object to MailItem.

好的,请使用"as"运算符来测试您感兴趣的接口,而不会引发异常.

OK use the "as" operator to test for the interface you are interested in without raising an exception.

这篇关于使用Outlook API打开电子邮件时引发错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆