I have a C# application that reads .msg files and extracts the body and the attachments. But when I try to load a .eml file the application crashes. I am loading the files l
CreateItemFromTemplate
only works with the MSG/OFT files.
Fot the EML files you will either need to parse the file explicitly in your code or use a third party library (such as Redemption):
The following code will create an MSG file and import an EML file into it using Redemption (RDOSession object):
set Session = CreateObject("Redemption.RDOSession")
Session.MAPIOBJECT = outlookApp.Session.MAPIOBJECT
set Msg = Session.CreateMessageFromMsgFile("C:\Temp\temp.msg")
Msg.Import "C:\Temp\test.eml", 1024
Msg.Save
MsgBox Msg.Subject
You can then use the message (RDOMail) to access it various properties (Subject, Body, etc.)