0

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['[email protected]']

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("[email protected]")
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)
7
  • What does "not working" mean? Are you getting an error? Or is the folder simply not set when you view the rules later? Commented Oct 20, 2020 at 22:41
  • Sorry, Dmitry, and thank you for pointing that out. The rule is created in outlook, the rule has a name and a condition, but the part of the rule about a destination folder is missing. I edited the question with these details. Commented Oct 21, 2020 at 15:22
  • Does it work if you point the rule to a folder in the default store (where you are creating the rule)? Commented Oct 21, 2020 at 16:57
  • @DmitryStreblechenko - Thanks for the attention! Actually, i do get an error with the code above. I just listed in the question. Sorry, my bad. Commented Oct 21, 2020 at 17:57
  • So, is the folder in question from a different store? Does it work with a folder from the primary store? Commented Oct 21, 2020 at 20:36

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.