Outlook 2002 and Later Code Sample
Starting with
Outlook
2002, you can call a VBA subroutine from a Rules
Wizard rule using the "run a script" rule action. The procedure can
be in either the built-in ThisOutlookSession module or any custom
module and must include a MailItem or MeetingItem argument. This short example
converts all incoming messages to plain text:
The other Outlook 2002 (or later) feature that makes this work is the BodyFormat property of the MailItem
object, which allows you to set a message's format. Note that
changing a message from HTML to plain text makes any embedded image
attachments inaccessible from the user interface. They are still
stored in the message, however, and can be accessed via code.
We have not done any testing to see how well the
"run a script" rule holds up when the user receives hundreds of
messages at one time.
NOTE:
To avoid security prompts when accessing
properties like Body and Recipients, you
must use the technique above to get the item
indirectly, through its EntryID property and
the Namespace.GetItemFromID method. If you
attempt to access MyMail.Body or
MyMail.SenderName, for example (MyMail being
the name of the parameter for the "run a
script" rule procedure), you will get a
security prompt.
WARNING:
We have seen a couple of instances where a machine running Outlook
2002 with such a rule completely loses the VbaProject.otm file that
contains all the Outlook VBA code. If you use "run a script" rules, be sure
to back up VbaProject.otm regularly or export the individual
modules.
This type of rule apparently should not be run by
Exchange Server users working offline. See
OL2002 Error Message The Message You Specified Could Not Be Found
When You Synchronize. Also see:
|