Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cassandra/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python-comtypes(工作)与pywin32(不工作)-使用Python创建outlook规则_Python_Outlook_Com_Pywin32_Comtypes - Fatal编程技术网

Python-comtypes(工作)与pywin32(不工作)-使用Python创建outlook规则

Python-comtypes(工作)与pywin32(不工作)-使用Python创建outlook规则,python,outlook,com,pywin32,comtypes,Python,Outlook,Com,Pywin32,Comtypes,(Windows 10、Office 365、Python 3.7、Pycharm) 我能够使用comtypes在outlook中成功创建规则: import comtypes.client o = comtypes.client.CreateObject("Outlook.Application") rules = o.Session.DefaultStore.GetRules() oRule = rules.Create("Test_Rule", 0

(Windows 10、Office 365、Python 3.7、Pycharm)

我能够使用comtypes在outlook中成功创建规则:

import comtypes.client

o = comtypes.client.CreateObject("Outlook.Application")
rules = o.Session.DefaultStore.GetRules()
oRule = rules.Create("Test_Rule", 0)

condition = oRule.Conditions

oFromCondition = oRule.Conditions.From
oFromCondition.Enabled = True
oFromCondition.Recipients.Add("john@email.com")
oFromCondition.Recipients.ResolveAll

condition.Enabled = True
root_folder = o.GetNamespace('MAPI').Folders['x@outlook.at']
dest_folder = root_folder.Folders["Posteingang"]

move = oRule.Actions.MoveToFolder
move.__MoveOrCopyRuleAction__com__set_Enabled(True)
move.__MoveOrCopyRuleAction__com__set_Folder(dest_folder)

rules.Save()
我无法使用pywin32使其正常工作。运行以下代码时,出现错误,无法创建规则:

import win32com.client as win32

o = win32.Dispatch("Outlook.Application")

caiok = o.GetNamespace("MAPI").Folders['x@outlook.at']

dest_folder = caiok.Folders["Posteingang"]
colRules = o.Session.DefaultStore.GetRules()
oRule = colRules.Create("New Rule10", 0)

oFromCondition = oRule.Conditions.From
oFromCondition.Enabled = True
oFromCondition.Recipients.Add("john@email.com")
oFromCondition.Recipients.ResolveAll

oMoveRuleAction = oRule.Actions.MoveToFolder
oMoveRuleAction.Enabled=True
oMoveRuleAction.Folder=dest_folder

colRules.Save()
错误:

Traceback (most recent call last):
  File "D:/wwo/scrapbookIII.py", line 20, in <module>
    colRules.Save()
  File "<COMObject GetRules>", line 2, in Save
pywintypes.com_error: (-2147352567, 'Ausnahmefehler aufgetreten.', (4096, 'Microsoft Outlook', 'Mindestens eine Regel kann aufgrund von ungültigen Aktionen oder Bedingungen nicht gespeichert werden.', None, 0, -2147467259), None)
回溯(最近一次呼叫最后一次):
文件“D:/wwo/scrapbookIII.py”,第20行,在
colRules.Save()
文件“”,第2行,保存
pywintypes.com_错误:(-2147352567,“Ausnahmefehler aufgetreten.”,(4096,“Microsoft Outlook”,“Mindestens eine Regel kann aufgrund von ungültigen Aktionen order Bedingungen nicht gespeichert werden.”,无,0,-2147467259),无)

我做错了什么?

Python要求paren调用函数。因此,这没有任何作用:

oFromCondition.Recipients.ResolveAll
你需要:

oFromCondition.Recipients.ResolveAll()

嗨,蒂姆!感谢您的输入,但在工作示例中,我不需要括号。