'pull all contacts out of Outlook

I'm trying to pull all my contacts out of Outlook.
I have tried many things but nothing works for me, I would love to hear from your experience what is the trivial way to do this.
This is one way I tried to do:

Using SPIRE.EMAIL


// Create an imapclient with host, user and password

        ImapClient client = new ImapClient();

        client.Host = "outlook.office365.com";

        client.Username = "#Your email address";

        client.Password = "#Your email password";

        client.ConnectionProtocols = ConnectionProtocols.Ssl;

        client.Port = 143;

        client.Connect();

        client.Select("Inbox");

        // Get a collection of messages

        var addressSet = new HashSet<string>();

        ImapMessageCollection msg = client.GetAllMessageHeaders();

        for (int i = 0; i < msg.Count; i++)

        {

            string address = msg[i].From.Address;

            addressSet.Add(address);

        }


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source