Reputation: 2244
Like the title says I want to add contacts to Outlook using Python. Currently I am using win32com
and can get all current contacts and print them out like so:
import win32com.client
import pywintypes
o = win32com.client.Dispatch("Outlook.Application")
ns = o.GetNamespace("MAPI")
contactsFolder = ns.GetDefaultFolder(10)
contacts = contactsFolder.Items
for c in contacts:
print(c)
However, I am uncertain on how to add new contacts. Any ideas on how this can be achieved? Thanks.
EDIT: Final solution
ContactItem = contactsFolder.Items.Add("IPM.Contact")
ContactItem.FullName = "John Doe"
ContactItem.Email1Address = "[email protected]"
ContactItem.Save()
Upvotes: 1
Views: 1142
Reputation: 66235
Call contactFolder.Items.Add("IPM.Contact")
- it will return an instance of the ContactItem object. Set its properties and call ContactItem.Save
.
Upvotes: 1