Outlook for Mac. How to convert OLM to PST?
Tags: csharp, api, productivity
Published: 2019-10-31 10:50:33

###Necessity
On the one hand, we have Mac OS as the second most popular operating system. On the other hand, we have Outlook as one of the most popular personal information managers in the world. So, it was a question of time when we were able to use all functions of Outlook on Mac.

Now we have Outlook for Mac OS provided by Microsoft Office. This application is a full-weight version of Outlook for Windows, but we can use it on Mac OS. There is only one difference. It is a storage file format. The version for Mac OS uses OML against PST on Windows.

So one of the most prevalent problems to solve is converting from OML files to PST. That can be done for many reasons: to send data on a Windows machine for some processing or to save data according to the saving data.

###Save and protect your data
One of the cases that users of Mac OS encounter are errors that occur when saving data and their further damage.
It can be caused by compatibility between MAC OS and Outlook for Mac. When these two applications don’t synchronize as well. Then Outlook can give various error messages or exceptions like:
**“Microsoft Outlook must be closed because an error occurred. Any unsaved work may be lost.”
“Sync pending for this folder”
“attachments exceed the limit allowed please remove attachments, sync error code 17193”**🤦‍♂️

**Do you save your outlook data and how do you do it?**
Share your comments below! 👇👇👇

You can go two ways:
    1. You can try to fix them to handle the compatibility issues doing: continuous updating to the latest updates or to export all the Outlook data in the OLM files using the Export option.
    2. Use [Aspose.Email](https://products.aspose.com/email?utm_source=https://dev.to/aspose_email/outlook-for-mac-how-to-convert-olm-to-pst-25p7&utm_medium=email) library to convert OML files to PST to save data to protect it or transfer.

###Usage

```c#
string dst = "SampleOLM.olm";

//Initialize Olm storage
using (OlmStorage storage = new OlmStorage(dst))
{
    //Initialize Pst storage
    using (PersonalStorage pst = PersonalStorage.Create("output.pst", FileFormatVersion.Unicode))
    {
        //Create only Inbox folder as an example
        FolderInfo pstFolder = pst.CreatePredefinedFolder("Inbox", StandardIpmFolder.Inbox);

        //Go through folders in the OLM storage
        foreach (OlmFolder folder in storage.FolderHierarchy)
        {
            //Check is this folder empty
            if (folder.HasMessages)
            {
                 // extract messages from folder
                 foreach (MapiMessage msg in storage.EnumerateMessages(folder))
                 {
                     //Add message to the pst storage
                     pstFolder.AddMessage(msg);
                     Console.WriteLine("Subject: " + msg.Subject);
                 }
            }
        }
    }
}
```

This approach is secure because you don’t have to send your data to a third-party server; all processes take place on your machine.
This library saves the integrity of the whole OLM file. Also, PST has a split feature that can allow users to divide a large PST file into smaller-sized PST files. 

After successful converting, the PST file can be saved on your machine or can be migrated to the Outlook for Windows or to the other applications which can support this file.

**Do you often face similar problems and how do you solve them?**
Leave your comments below. 👇👇👇