Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

Currently, 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?

like image 280
Matt Victory Avatar asked Oct 22 '09 16:10

Matt Victory


People also ask

How do I access an attachment in Outlook?

You can open an attachment from the Reading Pane or from an open message. In either case, double-click the attachment to open it. To open an attachment from the message list, right-click the message that has the attachment, click View Attachments, and then click the name of the attachment.

Where email attachments are stored?

Many e-mail programs (e.g., Microsoft Outlook, or Thunderbird), use a dedicated folder for storing message attachments. This folder may be located in C:\Users\<yourUserName>\. The folder is a temporary storage location, meaning that the files may be removed by the program at any time.


1 Answers

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.

like image 132
Robert Harvey Avatar answered Nov 16 '22 11:11

Robert Harvey