【发布时间】:2015-09-06 01:15:35
【问题描述】:
我正在尝试编写 Python 脚本/程序来关闭我在 Outlook 2010 中创建的电子邮件规则。
通过 VBA,我设法编写了一个函数,该函数将根据传入的布尔值打开和关闭一组规则名称。
Function toggleRules(ruleNames() As String, tf As Boolean) As Boolean
Dim olRules As Outlook.Rules
Dim olRule As Outlook.Rule
Dim blnExecute As Boolean
For Each Rule In ruleNames()
Set olRules = Application.Session.DefaultStore.GetRules
Set olRule = olRules.Item(Rule)
olRule.Enabled = tf
If blnExecute Then olRule.Execute ShowProgress:=True
olRules.Save
Set olRules = Nothing
Set olRule = Nothing
Next Rule
End Function
这有效,并且将打开/关闭我通过其他 VBA 函数按名称发送它的规则。如果你很好奇,目前当某个主题的任务提醒触发时,它会调用这个函数。
我想通过 python 来完成这个,所以我可以用更复杂的方法来触发它,而不仅仅是提醒计时器,这只是一般原因,我更喜欢这样做。好像用pywin32扩展就可以做到:
http://sourceforge.net/projects/pywin32/
但是,我很难进入“规则”界面。我可以访问 Outlook 应用程序和命名空间,但似乎不知道从这里去哪里。
import win32com.client
x = win32com.client.gencache.EnsureDispatch("Outlook.Application")
y = x.GetNamespace("MAPI")
最终我希望基本上拥有相同的功能,即给定一个名称列表和一个布尔值,让它在 Outlook 中切换这些规则。
谢谢。
【问题讨论】: