I've been trying really hard to make it work in python 3.7 and outlook 365. A related question here and the VBA documentation is here. I can't manage to solve it.
Everything in the code is working fine, except the two lines commented out in the code.
Please, help!
import win32com.client as win32
o = win32.Dispatch("Outlook.Application")
musterman = o.GetNamespace("MAPI").Folders['musterman@outlook.at']
dest_folder = musterman.Folders["Posteingang"].Folders["Ich"]
colRules = o.Session.DefaultStore.GetRules()
oRule = colRules.Create("New Rule", 0)
oFromCondition = oRule.Conditions.From
oFromCondition.Enabled = True
oFromCondition.Recipients.Add("john@email.com")
oFromCondition.Recipients.ResolveAll
oMoveRuleAction = oRule.Actions.MoveToFolder
oMoveRuleAction.Enabled = True #not working
oMoveRuleAction.Folder = dest_folder #not working
colRules.Save()
Error I get:
Traceback (most recent call last):
File "D:/OneDrive/Projekte/coding/python - working_with_outlook/scrapbookIII.py", line 21, 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)