1

I am trying to load Msg file to MailItem, I cannot find any method that can load from Stream or Array. I am forced to save the file on the Client PC. OOM I used

Application.CreateItemFromTemplate(path, Type.Missing)

I can delete the temp file right after the MailItem is created. RDO I found code

Session.GetMessageFromMsgFile(path);

I cannot delete the Msg file right after the RDOMail is created. I am coding in C#, how should I dispose the Msg?

Benzhi Pan
  • 161
  • 1
  • 14

1 Answers1

2

RDOSession.GetMessageFromMsgFile uses the MSG file for as long as the RDOMAil object is alive. After you are done using it, either release it using Marshal.ReleaseComObject or cast RDOMail to IDisposable and call IDisposable.Dispose.

The equivalent to Outlook's Application.CreateItemFromTemplate would be to create a new message in one of the Outlook folders (RDOFolder.Items.Add), and then import the MSG file using RDOMail.Import.

Dmitry Streblechenko
  • 62,942
  • 4
  • 53
  • 78
  • 1
    Thank you! Dmitry. `Marshal.ReleaseComObject(msg);` is not working. `var dis = msg as IDisposable; dis.Dispose();` works. I wonder if I use Dispose instead of Marshal.ReleaseComObject(mail) will get rid of Outlook crashing problem. Someone have more that half million items in their box. Do you have comment on this? – Benzhi Pan Aug 23 '18 at 09:19
  • Marshal.ReleaseComObject will work fine as long as you don't have any dangling references to the same message. – Dmitry Streblechenko Aug 23 '18 at 22:52