Read MS Outlook OLM Files in C# .NET

OLM is a file format which Microsoft Outlook for Mac uses to store local data. OLM contains local data such as emails, attachments, notes, calendar data, contacts, tasks, history, etc. OLM files is used by Outlook for Mac. Outlook for Windows can’t get access or open it. The version of Outlook for Windows supports only PST file format to store data. In this article we will consider how to open and read OLM format files from C# applications.

C# .NET API to Read OLM Files

Aspose.Email for .NET is a robust API that provides a range of features to implement email applications. Also, it allows reading OLM files and other mail storage formats such as MBOX, PST/OST. You can either install the library via NuGet or download its DLL.

PM> Install-Package Aspose.Email

Opening OLM format files

Aspose.Email API introduces two ways to open OLM format files:

There are differences in behavior between these methods. See section below.

Opening file by constructor

To open a file, you should call constructor of class OlmStorage and pass full file name or stream as an argument to it:

Opening file using static method FromFile

To open file you should use static method FromFile and pass full file name or stream as an argument to it:

Getting folders

After opening file using constructor, it will be accessible FolderHierarchy property. It returns list of directories which exists in OLM file. Every object of class OlmFolder of list has SubFolders property, which returns a list of subfolders. Thus, we have access to all the directories in OLM.

The example below displays list of all folders in hierarchical order:

If opening the file by using the FromFile method, then by default the FolderHierarchy property won’t be initialized and will return null. In this case, it’s necessary explicitly to call GetFolders method:

Also, it’s possible to get any folder by name. To do this you should:

  • call GetFolder method

  • to pass folder name as a first argument and value, which shows whether to ignore case sensitivity when searching for a folder, as the second parameter.

List of emails

OlmFolder class, which represents folder, has the following methods to get list of emails:

  • EnumerateMessages implements iteration of emails in a folder. In this case, every iteration returns OlmMessageInfo object, which provides short info about email.

  • EnumerateMapiMessages, also implements iteration of emails in a folder, but in this case, every iteration returns MapiMessage object, which represents the email itself, with all properties.

Using EnumerateMessages method

Using EnumerateMapiMessages method

Other useful properties

Also, OlmFolder class has HasMessages and MessageCount properties, which return the presence of messages in the folder and their count:

Extracting emails

OlmStorage class has ExtractMapiMessage method, which allows to extract emal. This method receives an OlmMessageInfo object.

Conclusion

In this article, you learned how to read OLM files in C#. You have seen the ways to get list of folders and extract messages from OLM file. Besides this, you can learn more about Aspose.Email for .NET using documentation. Also, you can share your questions or requests in our forum.

See Also