[python-win32] cde Outlook 2007 rules and python
nihil at blue.dyn-o-saur.com
nihil at blue.dyn-o-saur.com
Wed Mar 3 10:58:41 CET 2010
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("mail at 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"
More information about the python-win32
mailing list