[英]Get Outlook.MailItem from IMessage
I'm working on an Outlook add-in (VSTO, C#) that needs to be able to access the smime.p7m file from a signed or encrypted message. 我正在开发一个Outlook加载项(VSTO,C#),它需要能够从签名或加密的邮件中访问smime.p7m文件。 I know how to get the relevant
IMessage
, but I'm hoping to do this in C# without needing to implement too many COM wrappers. 我知道如何获取相关的
IMessage
,但是我希望在C#中实现此功能而无需实现太多的 COM包装器。 Here's what I've got so far: 到目前为止,这是我得到的:
I wrote a C# wrapper for IMAPISecureMessage
. 我为
IMAPISecureMessage
编写了C#包装器。 It's not long or complex. 它不长也不复杂。 I can take an
Outlook.MailItem
and get its MAPIOBJECT
property, which appears to just be the underlying IMessage
. 我可以使用
Outlook.MailItem
并获取其MAPIOBJECT
属性,该属性似乎只是基础IMessage
。 I can then cast that IMessage
to my IMAPISecureMessage
wrapper and call GetBaseMessage()
on it. 然后,我可以将该
IMessage
投射到我的IMAPISecureMessage
包装器上,并对其调用GetBaseMessage()
。 This all appears to work. 这一切似乎都起作用。
The problem is, this returns an IMessage
. 问题是,这将返回
IMessage
。 I need to extract the attachment (smime.p7m) from this IMessage
. 我需要从此
IMessage
提取附件(smime.p7m)。 I was hoping I could do that by wrapping a MailItem
around the returned IMessage
, but I can't find any way to do that. 我希望可以通过将
MailItem
包裹在返回的IMessage
周围来做到这一点,但是我找不到任何方法。 I can see how to create a MailItem
( Application.CreateItem
or Items.Add
), but I can't set the MAPIOBJECT
property of an existing MailItem
, and I don't see a way to create a MailItem
from an existing MAPI object (such as my IMessage
from GetBaseMessage()
). 我可以看到如何创建
MailItem
( Application.CreateItem
或Items.Add
),但是无法设置现有MailItem
的MAPIOBJECT
属性,也看不到从现有MAPI对象创建MailItem
的方法(例如来自GetBaseMessage()
IMessage
。
Is there a way to do create the desired MailItem
? 有没有一种方法可以创建所需的
MailItem
? If not, is there a way I can get the attachment (smime.p7m) out of the IMessage
without either implementing a whole bunch of COM interfaces or using a proprietary third-party library (such as Redemption)? 如果没有,有没有办法我可以从
IMessage
获取附件(smime.p7m),而无需实现大量COM接口或使用专有的第三方库(例如Redemption)?
You could of course create IMessage
, IMAPITable
, IAttach
interface definitions and call IMessage::GetAttachmentTable
, then IMAPITable::SetColumns
/ QueryRows
(or HrQueryAllRows
) to retrieve PR_ATTACH_NUM
, then call IMessage::OpenAttach
to open the attachment, then IAttach.OpenProperty(PR_ATTACH_DATA_BIN, IID_IStream, ...)
to open the binary data as IStream
. 您当然可以创建
IMessage
, IMAPITable
, IAttach
接口定义并调用IMessage::GetAttachmentTable
,然后IMAPITable::SetColumns
/ QueryRows
(或HrQueryAllRows
)来检索PR_ATTACH_NUM
,然后调用IMessage::OpenAttach
打开附件,然后IAttach.OpenProperty(PR_ATTACH_DATA_BIN, IID_IStream, ...)
以将二进制数据作为IStream
打开。
You can also try to change the message class of the message to IPM.Note
, save it, completely release (and pray Outlook does not keep a reference), then open it as a regular MailItem using Namespace.GetItemFromID
. 您还可以尝试将消息的消息类更改为
IPM.Note
,保存它,完全释放(并祈祷Outlook不保留引用),然后使用Namespace.GetItemFromID
其作为常规MailItem打开。
Or, as you mentioned, you can use Redemption and its RDOEncryptedMessage object. 或者,如上所述,您可以使用Redemption及其RDOEncryptedMessage对象。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.