none
Open an EML and forward it? RRS feed

  • Question

  • Hi

    How can I in and Outlook Add-in open an EML file from disk, "click forward" and show it for the user, so he can enter the forward text and send it?

    My code (which doesn't work) looks like this:

    Dim filename As String = "D:\email_test.eml"
    Dim mail As Outlook.MailItem = CType(Me.Application.CreateItemFromTemplate(filename), Outlook.MailItem) ' Doesn't work
    Dim forwardEmail As Outlook.MailItem = mail.Forward
    forwardEmail.Display()
    

    Thanks :)

    Monday, February 8, 2016 10:09 AM

Answers

  • 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()
      


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!


    Monday, February 8, 2016 1:37 PM

All replies

  • 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()
      


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!


    Monday, February 8, 2016 1:37 PM
  • Hi Dmitry

    I tried using Redemption and I have 2 issues..

    1. External/linked images are not shown in the forwardedMail.

    2. Closing Outlook asks me if I want to save changes eventhough I already closed the forwardedMail.

    Any idea?

    Thanks :)

    Monday, February 8, 2016 9:07 PM
  • 1. Are these external images or embedded as attachments? In the former case, try to set the RDOMail.DownloadPictures property to true before saving

    2. You might want to completely release the forwardedMail variable using Marshal.ReleaseComObject.


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Monday, February 8, 2016 10:40 PM