Weiß jemand, wie ich mit Python die Daten zu einem Kontakt in Outlook verändern kann? Am liebsten über Angabe des Vor- und Nachnamens den Kontakt finden und dann gezielt eine Telefonnummer o.ä. ändern.
Folgendes habe ich versucht und es klappt nicht
Ich bekomme lediglich zweimal den kompletten Namen und die private Tel.-Nr. vom zweiten Kontakt in meiner Kontaktliste. Geändert hat sich nix...
Code: Alles auswählen
#!/usr/bin/python2.5
# -*- coding: iso-8859-1 -*-
# File: outlook_change_contact.py
import win32com.client
class MSOutlook:
def __init__(self):
self.outlookFound = 0
try:
self.oOutlookApp = \
win32com.client.gencache.EnsureDispatch("Outlook.Application")
self.outlookFound = 1
except:
pass
self.records = []
def changeContact(self):
if self.outlookFound:
onMAPI = self.oOutlookApp.GetNamespace("MAPI")
ofContacts = onMAPI.GetDefaultFolder(win32com.client.constants.olFolderContacts)
no = 2
print ofContacts.Items.Item(no).FullName
print ofContacts.Items.Item(no).HomeTelephoneNumber
ofContacts.Items.Item(no).HomeTelephoneNumber = '+4930797979'
ofContacts.Items.Item(no).FirstName = 'aaa'
ofContacts.Items.Item(no).Save()
print ofContacts.Items.Item(no).FullName
print ofContacts.Items.Item(no).HomeTelephoneNumber
if __name__ == '__main__':
oOutlook = MSOutlook()
oOutlook.changeContact()
JR