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

查看:30
本文介绍了从 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天全站免登陆