Fetching Outlook Contacts with Python

outlook, python

Solution

import win32com.client
import pywintypes

o = win32com.client.Dispatch("Outlook.Application")
ns = o.GetNamespace("MAPI")
profile = ns.Folders.Item("Profile Name")
contacts = profile.Folders.Item("Contacts")

Problem

I am given a task to fetch all the contacts from (Microsoft)Outlook using Python. I tried this : ``` import win32com.client object = win32com.client.Dispatch("Outlook.Application") ns = object.GetNamespace("MAPI") print ns ``` It gave me the output : ``` <win32com.gen_py.Microsoft Outlook 12.0 Object Library._NameSpace instance at 0x12528376> ``` I understand that `ns` is now an Object but does it give me access to `Outlook` contacts ? If yes then how should I fetch the contacts ? Thank You.

Original source