Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fetching Outlook Contacts with Python

Tags:

python

outlook

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.

like image 411
Nagri Avatar asked Oct 08 '22 04:10

Nagri


1 Answers

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")
like image 160
Vinayak Kolagi Avatar answered Oct 12 '22 09:10

Vinayak Kolagi