从Python修改Microsoft Outlook联系人 [英] Modifying Microsoft Outlook contacts from Python

查看:141
本文介绍了从Python修改Microsoft Outlook联系人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

过去,我已经编写了一些Python工具来从Outlook联系人中提取数据.现在,我正在尝试修改我的Outlook联系人.我发现Outlook注意到了我的更改,但并没有坚持.我似乎要更新一些缓存,而不是真实记录.

I have written a few Python tools in the past to extract data from my Outlook contacts. Now, I am trying to modify my Outlook Contacts. I am finding that my changes are being noted by Outlook, but they aren't sticking. I seem to be updating some cache, but not the real record.

代码简单明了.

import win32com.client
import pywintypes

o = win32com.client.Dispatch("Outlook.Application")
ns = o.GetNamespace("MAPI")
profile = ns.Folders.Item("My Profile Name")
contacts = profile.Folders.Item("Contacts")
contact = contacts.Items[43] # Grab a random contact, for this example.
print "About to overwrite ",contact.FirstName, contact.LastName
contact.categories = 'Supplier' # Override the categories

# Edit: I don't always do these last steps.
ns = None 
o = None

这时,我切换到Outlook,它已打开到详细地址卡"视图.

At this point, I change over to Outlook, which is opened to the Detailed Address Cards view.

我查看了联系人摘要(未打开),并且类别未更改(未刷新?).

I look at the contact summary (without opening it) and the category is unchanged (not refreshed?).

我打开了联系人,并且其类别已更改,有时. (不确定什么时候,但是感觉好像与缓存有关.)如果更改了,关闭它时会提示我保存更改,这很奇怪,因为我没有在Outlook UI中进行任何更改.

I open the contact and its category HAS changed, sometimes. (Not sure of when, but it feels like it is cache related.) If it has changed, it prompts me to Save Changes when I close it which is odd, because I haven't changed anything in the Outlook UI.

如果我退出并重新启动Outlook,更改将消失.

If I quit and restart Outlook, the changes are gone.

怀疑我无法致电 SaveChanges ,但是我看不到哪个对象支持它.

I suspect I am failing to call SaveChanges, but I can't see which object supports it.

所以我的问题是:

  • 我应该打电话给SaveChanges吗?如果是这样,它在哪里?
  • 我是否犯了其他一些愚蠢的错误,导致我的数据被丢弃了?

推荐答案

我认为联系人上有一个.Save()方法,因此您需要添加:

I believe there is a .Save() method on the contact, so you need to add:

contact.Save()

contact.Save()

这篇关于从Python修改Microsoft Outlook联系人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆