I try to translate this vbs script to python. http://www.outlookcode.com/threads.aspx?forumid=2&messageid=29505 The purpose of this script is to automatically create an rule in Outlook to sort incoming messages. It is possible to do this in Outlook 2007 and the vbs file works. The SPAM folder is writable so thats not the problem.
This code works but only creates an rule that forwards the messages to an another mail address: #!/bin/env python # -*- coding: UTF-8 -*- import codecs import tempfile import win32api import win32com.client import sys,os constants = win32com.client.constants application = win32com.client.Dispatch("Outlook.Application") rules = application.Session.DefaultStore.GetRules() _folder = application.Session.GetDefaultFolder(constants.olFolderInbox) _spamfolder = _folder.Folders["Spam"] _rule = rules.Create("SPAM",constants.olRuleReceive) _condition = _rule.Conditions.MessageHeader _condition.Text = ["X-Spam-Status: Yes"] _condition.Enabled = True _action = _rule.Actions.Forward _action.Recipients.Add("m...@mail.com") _action.Enabled = True _rule.Enabled = True rules.Save() This is the code i need but it is not working: #!/bin/env python # -*- coding: UTF-8 -*- import codecs import tempfile import win32api import win32com.client import sys,os constants = win32com.client.constants application = win32com.client.Dispatch("Outlook.Application") rules = application.Session.DefaultStore.GetRules() _folder = application.Session.GetDefaultFolder(constants.olFolderInbox) _spamfolder = _folder.Folders["Spam"] _rule = rules.Create("SPAM",constants.olRuleReceive) _condition = _rule.Conditions.MessageHeader _condition.Text = ["X-Spam-Status: Yes"] _condition.Enabled = True _action = _rule.Actions.MoveToFolder _action.Folder = _spamfolder _spamfolder2 = _spamfolder print _spamfolder, _spamfolder2, _action.Folder _action.Enabled = True _rule.Enabled = True rules.Save() The problem is that even after the assignment and in my print _action.Folder contains None but _spamfolder and _spamfolder2 both contain an reference to the Library.MAPIFolder. Could anyone please enlighten me. Why is _action.Folder empty? It seems the vbs guys have the same problem but they use "Set objActionMoveToFolder.Folder = objFolderJunk" instead of "objActionMoveToFolder.Folder = objFolderJunk" _______________________________________________ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32