0
votes

I am writing VSTO Outlook add-in that needs to save some items as msg files. The problem is, each time I call MailItem.SaveAs it causes Outlook to lag slightly and show processing cursor (blue circle). I have tried moving it int a separate thread, but that does not help. Saving item is quite fast (less than 100 ms most of the time), but still causes this annoying behavior. I need to save an item to read it as MSG format, so if I can do this directly this would be even better, but as I found here: Outlook MailItem as Stream the only solution seems to use EWS for this. Are there other alternatives?

Maybe using RDO can help in this case? Another option, as I understand, create msg manually from mail item properties. But maybe there is an easier way?

1
Have you tried to use RDO? It can be used on a secondary thread.Dmitry Streblechenko
Yes, I was thinking about it. Will give it a try.Sergey Belikov
Creating Redemption SafeMailItem from Outlook MailItem and saving it seems to help. But I have some questions. Is it safe to call Marshal.ReleaseComObject for an item after SafeMailItem is created with Item set? Does it hold any references or just copy data? And saved msg differs a little from the one I get from Outlook. For example, for messages with empty subject it shows [UNREGISTERED] in subject.Sergey Belikov
Yes, Marshal.ReleaseComObject is safe - it just ensures that the COIM object is released immediately rather than later on the GC thread.[UNREGISTERED] is added by the dev version - it is not present in the distributable version.Dmitry Streblechenko

1 Answers

3
votes

Unlike OOM, a low level API on which Outlook is based on (Extended MAPI) supports multithreading. So, you can run the code on a secondary thread without any visible impact to the Outlook UI. See INFO: Save Message to MSG Compound File for more information.

Also you may consider using third-party wrappers around Extended MAPI such as Redemption.