I'm trying to create a bunch of Outlook rules automatically. I'm using Python 2.7, win32com, and Outlook 2007. To do this I must create a new Rule object and specify a folder for its move action. However, I can't set the Folder property successfully -- it just stays None despite me giving an object of the right type.
import win32com.client
from win32com.client import constants as const
o = win32com.client.gencache.EnsureDispatch("Outlook.Application")
rules = o.Session.DefaultStore.GetRules()
rule = rules.Create("Python rule test", const.olRuleReceive)
condition = rule.Conditions.MessageHeader
condition.Text = ('Foo', 'Bar')
condition.Enabled = True
root_folder = o.GetNamespace('MAPI').Folders.Item(1)
foo_folder = root_folder.Folders['Notifications'].Folders['Foo']
move = rule.Actions.MoveToFolder
print foo_folder
print move.Folder
move.Folder = foo_folder
print move.Folder
# move.Enabled = True
# rules.Save()
Prints
<win32com.gen_py.Microsoft Outlook 12.0 Object Library.MAPIFolder instance at 0x51634584> None None
I've looked at the code generated by makepy
when using win32com in non-dynamic mode. The class _MoveOrCopyRuleAction
has an entry for 'Folder'
in its _prop_map_put_
dict, but other than that I'm stumped.