win32com.client (Howto edit Contacts in Outlook)
mail at timgolden.me.uk
Fri Jul 11 15:09:24 CEST 2008
Bill Davy wrote:
> and since then have been busy with work, and my other job, and the garden.
Aha! So you're English, are you? Looks like you're in the West Country.
Weather map suggests you're not short of rain over there :)
> Now I am back looking at this (and using WInUSB to talk to a Maxim 3421E etc
> etc but that's another story). So any help today will be much appreciated.
Can't remember what the particular obstacles were you
were facing, but this runs OK on my setup -
Python 2.5.2 / pywin32 211 / Outlook 2003:
import os, sys
constants = win32com.client.constants
def items (contacts):
items = contacts.Items
item = items.GetFirst ()
item = items.GetNext ()
# Add whatever fields you like from:
FIELDS = ['FullName', 'CompanyName', 'Email1Address']
outlook = win32com.client.gencache.EnsureDispatch ("Outlook.Application")
ns = outlook.GetNamespace ("MAPI")
for contact in items (ns.GetDefaultFolder (constants.olFolderContacts)):
if contact.Class == constants.olContact:
for field in FIELDS:
print " ", field, "=>", getattr (contact, field, "<Unknown>")
Hope that helps.
More information about the Python-list