You can use a foreach loop to iterate through the attachments collection and list the attachments. MapiMessage.Attachments property returns the object of type MapiAttachmentCollection. MapiMessage class provides the Attachments collection for getting all the attachments in the message (msg) file. Getting the Attachments From Msg File and Saving to Disk text bodyif (msg.Body != null)Console.WriteLine(msg.Body) elseConsole.WriteLine("no text body.") // rtf bodyif (msg.BodyRtf != null)Console.WriteLine(msg.BodyRtf) elseConsole.WriteLine("No Rtf body.") ' text bodyIf Not msg.Body Is Nothing ThenConsole.WriteLine(msg.Body)ElseConsole.WriteLine("no text body.")End If' rtf bodyIf Not msg.BodyRtf Is Nothing ThenConsole.WriteLine(msg.BodyRtf)ElseConsole.WriteLine("No Rtf body.")End If We can get Text and Rtf body of the message by using properties of MapiMessage class. Getting the Text Body and Rtf Body of the Message subjectif (msg.Subject != null)Console.WriteLine(msg.Subject) elseConsole.WriteLine("no subject") // senderif (msg.SenderEmailAddress != null)Console.WriteLine(msg.SenderEmailAddress) elseConsole.WriteLine("No sender") // toif (msg.DisplayTo != null)Console.WriteLine(msg.DisplayTo) elseConsole.WriteLine("No one in To") // ccif (msg.Displa圜c != null)Console.WriteLine(msg.Displa圜c) elseConsole.WriteLine("No one in cc") ' subjectIf Not msg.Subject Is Nothing ThenConsole.WriteLine(msg.Subject)ElseConsole.WriteLine("no subject")End If' senderIf Not msg.SenderEmailAddress Is Nothing ThenConsole.WriteLine(msg.SenderEmailAddress)ElseConsole.WriteLine("No sender")End If' toIf Not msg.DisplayTo Is Nothing ThenConsole.WriteLine(msg.DisplayTo)ElseConsole.WriteLine("No one in To")End If' ccIf Not msg.Displa圜c Is Nothing ThenConsole.WriteLine(msg.Displa圜c)ElseConsole.WriteLine("No one in cc")End If
HOW TO VIEW MSG FILES CODE
Following is the sample code for getting these properties. MapiMessage class exposes properties and collections for getting subject, to, cc and from. MapiMessage msg = MapiMessage.FromFile(“C:\\SomeFolder\\SomeMsgFile.msg”) Dim msg As MapiMessage = MapiMessage.FromFile(“C:\\SomeFolder\\SomeMsgFile.msg”) Getting the From, To, Cc and Subject from Msg File You can load the msg file using a single line of code by calling FromFile() static method and passing the path of the msg file. In this section, we will present the code that we used in the demo to show the msg file contents.Īspose.Network library provides MapiMessage class for loading and parsing msg files.
HOW TO VIEW MSG FILES HOW TO
How to Parse and View Msg File contents Programmatically A separate Outlook msg Viewer Demo (attached with this article) is also available to guide you for parsing and reading Outlook. msg files using your own code in C# applications where Microsoft Office Outlook is not required for it. This article shows that how can you parse and view Outlook.