开发者

How do I access an Outlook email attachment in C# without saving it to a new location?

I am using Microsoft.Office.Interop.Outlook in C# to access a mailbox and find messages with specific file attachments. I need to interact with the attachments.

C开发者_JAVA技巧urrently, I am saving the file to a new location and accessing it from there. This copying process is slowing me down. I'd ideally like to access the file from wherever it is being stored in memory, but the Outlook.Attachment.PathName field is returning null.

The messages are being stored on an Exchange server.

Is it possible to access them directly or do I need to continue saving the files?


Outlook.Attachment.PathName implies a disk location. The attachment is a file; if you want to interact with it, you have to treat it like a file, and that means saving it out to the local disk.

The Outlook.Attachment object does not actually contain the attached file; it contains a link to the attached file, with some associated metadata.


I don't know if its possible in any way via the Outlook Object Model, but MAPI surely allows you that.

You need to open the messages MAPIObject, an IMessage. From there use IMessage::OpenAttach(), which returns an IAttach.
The attachment size is stored in PR_ATTACH_SIZE, the actual data in PR_ATTACH_DATA_BIN.

As always, Redemption probably has an easier way of doing this.

edit:
Access via MAPI is what Outlook does internally anyway - should be reasonably fast, at least when using Exchange Cached Mode.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜