4

Is it possible to return a MailItem directly as a Stream? (MailItem from Microsoft.Office.Interop.Outlook)

Now I have found a temporary solution to first save a MailItem to a directory, opening it and returning the stream to the file and afterwards deleting the file again.

This temporary solution is slow when processing lots of emails and I would like to replace it with e.g. returning a MailItem as MemoryStream directly.

How can this be done?

(Edit due to comments: being slow is one part, but another codepart (that cannot be modified) only accepts a Stream, that's way I'm looking for a solution to open a MailItem as a Stream)

juFo
  • 17,849
  • 10
  • 105
  • 142
  • 2
    I process upto 600 msgs in a minute or so just by using the mailitem direct - this in no way forms part of the answer so Im curious why you need a stream? – BugFinder Jun 27 '12 at 13:59
  • 1
    You could try using [EWS instead of VSTO](http://msdn.microsoft.com/en-us/library/dd637749%28v=exchg.80%29.aspx). There is no way to access a `MailItem` as a `MemoryStream` unless you're using the **clipboard** or **drag-n-drop**. – SliverNinja - MSFT Jun 27 '12 at 14:51
  • A similar question I have found: http://stackoverflow.com/questions/9595440/getting-system-net-mail-mailmessage-as-a-memorystream-in-net-4-5-beta – juFo Apr 06 '13 at 11:24

1 Answers1

0

I had a thought to your slow problem. I ran across something that may make a massive difference when writing mine.

When I had outlook in non cached mode, retrieving and opening each email, then moving it to a processed folder was arduous to say the least. When I had it in cached mode, of course I had to write code to ensure it had bothered to sync everything so I had uptodate info before I started.

When its cached you can open many many mail items at the same time, and parallel process, where as often in non cached mode it will stop you at around 32! and its idea of open (and ours) differ.

So, I also tried a imap class, sheesh lets never talk of that again what a mistake.

If you have some code, maybe we can help? If you dont have cached mode, I can probably dig out my how I forced it to sync everything code, it wasnt as nice and simple (I may have missed somethhing) as I thought but it works very reliably and now processes all the backup emails I get..

BugFinder
  • 17,474
  • 4
  • 36
  • 51
  • well being slow is one thing but I need the MailItem as a Stream (a Stream is the only thing that gets accepted). So that's way I would like to know how to get a MailItem directly as a Stream. – juFo Jun 27 '12 at 18:47
  • What needs a stream? I havent tried it, under Delphi you could have made a memory stream, and written the body text to that stream to read it back with another.. Or, I guess you could write all the mails out unix style into a text file and read that as a stream.. what needs a stream as input? Perhaps we can force it to do something else? – BugFinder Jun 27 '12 at 21:20