Parsing Microsoft Outlook Message Files
Contents
[
Hide
]
With Aspose.Email, you can parse Microsoft Outlook messages in just a few lines of codes. This article shows how. Aspose.Email has classes for performing many programming tasks with Outlook messages. The code example below shows how to:
- Load an email message.
- Get the email subject.
- Get the name of the sender.
- Get the full message body.
- Find out if there are attachments.
- Get the file names of any attachments and save them.
The following code snippet shows you how to parse Microsoft Outlook message files.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// The path to the File directory and Load Microsoft Outlook email message file | |
string dataDir = RunExamples.GetDataDir_KnowledgeBase(); | |
MapiMessage msg = MapiMessage.FromFile(dataDir + "message3.msg"); | |
// Obtain subject of the email message, sender, body and Attachment count | |
Console.WriteLine("Subject:" + msg.Subject); | |
Console.WriteLine("From:" + msg.SenderName); | |
Console.WriteLine("Body:" + msg.Body); | |
Console.WriteLine("Attachment Count:" + msg.Attachments.Count); | |
// Iterate through the attachments | |
foreach (MapiAttachment attachment in msg.Attachments) | |
{ | |
// Access the attachment's file name and Save attachment | |
Console.WriteLine("Attachment:" + attachment.FileName); | |
attachment.Save(dataDir + attachment.LongFileName); | |
} |