MojoDK February 2016

Open EML file in Outlook using Add-In?

Using Outlook Add-In (VSTO) can I open an EML file from disk and "display" it?

I've tried this...

Dim filename As String = "c:\test\_test.eml"
Dim mail As Outlook.MailItem = CType(Globals.ThisAddIn.Application.Session.OpenSharedItem(filename), Outlook.MailItem)
mail.Display()

But Outlook throws an exception saying path is not valid even though it is.

Any idea?

Answers


Dmitry Streblechenko February 2016

OpenSharedItem does not work with EML files. Outlook Object Model would not let you access EML files. You can either

  1. Parse the EML file (or use an available component), create new item in Outlook and set all properties one at a time

  2. If you were using C++ or Delphi, you could have used IConverterSession MAPI interface to import the data

  3. If using Redemption is an option, you can use something like the following (off the top of my head):

    dim Session as Redemption.RDOSession = CreateObject("Redemption.RDOSession") Session.MAPIOBJECT = Me.Application.Session.MAPIOBJECT dim Drafts as Redemption.RDOFolder = Session.GetDefaultFolder(olFolderDrafts) dim mail as Redemption.RDOMAil = Drafts.Items.Add mail.Sent = true mail.Import "c:\temp\test,eml", 1024 'olRfc922 mail.Save 'now reopen in OOM dim oMail as Outlook.MailItem = Me.Application.Session.GetItemFromID(mail.EntryId) dim forwardedMail as Outlook.MailItem = oMail.Forward forwardedMail.Display()

Post Status

Asked in February 2016
Viewed 1,124 times
Voted 7
Answered 1 times

Search




Leave an answer