5

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.

Nagri
  • 3,008
  • 5
  • 34
  • 63

1 Answers1

4
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")
Vinayak Kolagi
  • 1,831
  • 1
  • 13
  • 26