![]() |
|
||||
Creating Folder Scripts
'------------------------------------------------------------------------------
Option Explicit '------------------------------------------------------------------------------
'------------------------------------------------------------------------------
' DESCRIPTION: This event is fired when a new message is added to the
folder
' DESCRIPTION: This event is fired when a message in the folder is changed
' DESCRIPTION: This event is fired when a message is deleted from the
folder
' DESCRIPTION: This event is fired when the timer on the folder expires
</SCRIPT> As you can see, the script does nothing. For subroutines are provided,
one for each type of event (message creation, change or deletion, and a
timer event), but they are empty. Save the script without introducing any
changes.
Examining the System with Empty Script To see whether we are on track here after introducing a script that
does nothing let us examine the folder's associated contents table to see
a pair of hidden messages. They define this script, have the subject equal
to the name of the agent, and have IPC.Microsoft.ICS.EventBinding and IPC.Microsoft.EventBinding
message classes. Also, if you stop and restart the Event Service, you should
see a message (Event ID 16388) in the Application Event Log that this folder
is now monitored. Also, try to post a message to the folder and observe
that the system behaves normally doing nothing. An indication of normal
operation would be absence of any error messages in the Application Event
Log 1 minute or more after postings. As I have described earlier, 1 minute
is the default delay between communicating content changes from Exchange
information store to Event service.
Examining the System Behavior with Bogus Script The next logical step would be modifying the script to do something. Let's try to introduce a bogus command and see what happens. Modify the Folder_OnMessageCreated subroutine by introducing a command that VBScript will be unable to execute, like here: Public Sub Folder_OnMessageCreated
Save the script and post a message to the folder. Give the system enough time to process the event (2 minutes or more) and then examine the Application Event Log. You should see there a MSExchangeES Event ID 12 describing the error occurred: "A fatal error (0x86664004) occurred in an IExchangeEventSink while processing message [Subject = "My Subject"]. 09/06/98 15:27:53 Run time error at line 19. Source: Microsoft VBScript runtime error Error: 800a01f4. Description: Variable is undefined: "MyBogusCommand" followed by Event ID 25: "Script failed with a run time or syntax error on the last event. Since
the script was not modified since the last failure, the script will not
be run again until the error is fixed. Please refer to agent log for more
information about the failure."
Testing a Good Script Let's replace an invalid command with something that makes sense. Perhaps a good example would be trying to output some debugging information. This may be accomplished by utilizing the Script.Response object as in this example: Public Sub Folder_OnMessageCreated
If you test this modified script, you normally should not see any errors. Also, debug information that the script writes will be available if you press the "Logs..." button on Agent Edit dialog. Notice that errors are also logged there. Alternatively, you could try the following more interesting example, that automatically sends a reply to message originator: Public Sub Folder_OnMessageCreated
'Create a new message
'Set subject and body
'Send the message
Now if somebody posts a message to this public folder, a reply "Hello,
world!" message will be sent automatically back. For this illustration
code as pretty much for every sample code in this book I have removed all
error handlers. For example, the Resolve method may fail if mailboxes with
similar names exist (such as Test and Test1), and you are posting a message
using one of these mailboxes. Apparently, a proper error handling of all
possible errors is needed for production code. If your script fails it
will be immediately disabled by Exchange server.
Limitations of Folder Scripting
The following objects are created by Exchange server and passed to the processing script:
|