I've found that auto-forwarding messages using the Rules Wizard can be spotty at bestespecially when the destination is an Internet address. While there are workarounds to help you auto-forward all messages sent to a particular mailbox, your choices are somewhat more limited if you want to specify criteria.
In this instance I decided to create a server-side script that automatically forwards all messages sent with high importance to the e-mail address of my text pager. I did this for two reasons. First, it's a handy capability; second, it's a good excuse to write some basic message-handling code.
There are a couple of things you'll want to do on your Exchange Server first to make sure that the script will work:
- Configure your Internet Mail Service to allow auto-forwarded messages to get onto the Internet.
- Make sure that the scripting agent is installed and you have the proper client permissions to create a script.
NOTE: For instructions on how to install the scripting agent and assign the client permissions, see this article from the Microsoft Knowledge Base: "Automatic Resource Booking Available with Sample Scripts" (Q178351).
Now that you've made sure the script you write will work, you're ready to start coding:
- Right-click on your Inbox, choose Properties, and go to the Agents tab.
- Click the New button to create a new script and check the "A new item is posted in this folder" choice.
- Click Edit Script.
The rudimentary framework of the script is already created for you; all you need to do is add your own code to make it work. Let's take a look at some of the key components and what they do. Keep in mind that this is a simple example that you can personalize for your own tastes. You may even want to add features to your version.
Setting Constants
There are a couple of constants that you will want to work with throughout your script, so create a section for them just above the Global Variables section:
'-------------------
' Constants
'-------------------
These first two lines declare the constants that you're working with. The first is for the e-mail address of the pager and the second is just a documentation tool that I like to use; it lets me implant the version number in the code for my own reference:
Dim Const_Pager
Dim Const_Ver
Some people also add a constant for checking the message importance, like so:
Dim Const_CDOHigh
But for this script, in the name of simplicity, let's just work directly with the High importance value, which is 2. (Low is 0 and Normal, the default, is 1.)
Go ahead and set those constants to their values. There are other ways to get the pager address into the script, but I find it simpler just to use the Constant because it rarely, if ever, changes. If you're creating this script for a number of different users you might want to use some kind of variable or reference an Address Book entry instead.
NOTE: If you want to simplify things even further you could forgo using the constant for the pager address and just put the pager address directly into the code.
Const_Pager = "pager_address@pagingco.com"
Const_Ver = "1.1" 'Commented out the Err Clear to troubleshoot
If you're using Const_CDOHigh to check for importance, add this:
Const_CDOHigh = 2
Coding the Action
Start coding the action of your script. The Scripting Agent has conveniently created a "Public Sub" for you, so you only need to insert your code between the "Public Sub" and "End Sub" lines. Because you want this code to fire away when a message is created, use the "Public Sub Folder_OnMessageCreated" action:
' DESCRIPTION: This event is fired when a new message is added to the folder
Public Sub Folder_OnMessageCreated
Define some variables to use. Note that the names of these variables were arbitrarily selected. I like to use the prefix "o" to indicate an object; some people use "obj".
DIM oMsg 'The message being received
DIM oPage 'The outgoing message to the pager
DIM oRecipient 'The pager number to send to
Now you retrieve the newly arrived message:
Set oMsg = EventDetails.Session.GetMessage(EventDetails.MessageID,Null)
Your first step is to see whether the message meets your criteria. Remember that 2 is the value for the importance field of a high-importance message. If you are using the Constant method, substitute "g_Const_CDOHigh", where the number 2 is in the code below (I defined it above):
If oMsg.Importance = 2 Then
Having determined that the incoming message does have high importance, you now have to take your action:
set oPage = oMsg.Forward
oPage.Text = oMsg.Text
set oRecipient = oPage.Recipients.Add
oRecipient.Name = Const_Pager
oRecipient.Resolve
Use the Forward method to set the outgoing message (oPage) to be a forwarded message item and then set the text of the Page object to be the text from the incoming message. After that, use the Add method to get your Pager address into the To field of the outgoing message, setting oRecipient.Name to the constant for the pager (or the pager address itself if you've decided to simplify and not use the constant). Finally, call the Resolve method to resolve the address and assign the Entry ID.
Now you can end your If statement, send your message, and conclude your script:
oPage.Send
End If
Forwarding a message to an Internet address based upon your own criteria can sometimes be a hit-and-miss proposition with Outlook's Rules Wizard. Although you set this particular script up to forward messages based upon priority to a text pager, you could just as easily have selected other criteria and had them forward e-mail to a personal address or even another person entirely. By using these techniques, you can create your own server-side scripts that manipulate your e-mail reliably.