Skip navigation

Using WebCheck with CDO

Downloads
8119.zip

In "Setting Up WebCheck" (December 1999), I explored the WebCheck utility from the Microsoft Windows Internet Information Server Resource Kit. This utility can monitor your Web site and report when it or other parts of your server aren't working. However, WebCheck works with the mail component on Microsoft Site Server or the Microsoft Commercial Internet System (MCIS). Therefore, if you haven't installed Site Server or MCIS, you can't use the email feature as WebCheck currently implements it. To address this situation, I modified WebCheck to use Collaboration Data Objects for Windows NT Server (CDONTS) instead of the mail component. (CDONTS installs with various Microsoft software products, and you can find it on most systems. You can also download the latest version at http://www.microsoft.com/exchange/55/downloads/cdo.htm.)

To make this modification, you must have installed CDONTS on your system. (You need CDONTS to register the CDONTS component and to test the application.) When WebCheck with CDO is working, you can compile it and move it to other servers. You also need Visual Basic (VB) 6.0 to modify and recompile webcheck.vbp. You can use any version of VB 6.x.

Modifying WebCheck
To begin the modification, open webcheck.vbp in VB by either double-clicking webcheck.vbp in Windows Explorer or starting VB and choosing File, Open, webcheck.vbp. When webcheck.vbp is open in VB, you can begin to modify it. First, create a project reference to the CDONTS library (i.e., a reference in webcheck.vbp to cdonts.dll). To create the reference,

  1. Choose Project, Project References.
  2. Select the Microsoft CDO for NTS 1.2 Library check box, which you see in Screen 1. (I use CDONTS 1.2, but CDONTS 1.21 is now available at the URL shown above.)
  3. Click OK to place the reference to CDONTS in the project .vbp file.

At this point, you have linked CDONTS into the WebCheck application.

Now, to use CDONTS, you must modify the CreateMail procedure that executes WebCheck's mail function. First, find the procedure CreateMail in main.bas. (You can search for procedures by pressing Ctrl+F to display the Find dialog box.) The original code for CreateMail appears in Listing 1.

The Select Case statement in the original code checks the value in the g_iMailToUse variable, which WebCheck set earlier by reading from the webcheck.ini file. Then, use either Site Server or MCIS to execute the proper case statement to send email. You can modify the CreateMail procedure one of two ways.

To replace the code in CreateMail with your CDONTS code,

  1. Copy the code from CreateSMTPMail, and paste it into CreateMail.
  2. Remove the existing code from the CreateMail procedure. (This step leaves the procedure block empty.)

Now you can begin to modify the new code in CreateMail. First, change the error-handler label by changing two lines of code. The first line starts with On Error. The line ends with the error-handler label the code branches to if an error occurs.

Change this label to ErrorCreateMail to properly reflect the name of the procedure. Then, change the label itself, which is the line ending in a colon (:). The new label is

ErrorCreateMail:

Next, comment out the two lines that use SMTP to do all the work by placing a single quotation mark (') at the beginning of each line:

'Set smMail = CreateObject
("mps.sendmail")
'iMailSent = smMail.sendMail
(sMailFrom, g_sPageMailTo, sMessageSubject,

Commenting out the code takes it out of execution but leaves it in the application. Because you're going to replace this code with CDONTS, the new version of WebCheck won't need it.

Next, add a new CreateObject statement to create an instance of CDONTS.NewMail. This code creates an instance of the NewMail object in the CDONTS component. I placed this statement early in the procedure, but it can go anywhere as long as it occurs before the point at which WebCheck uses any of the NewMail objects. The statement looks like this:

Set oMail = CreateObject
("CDONTS.NewMail")

Next, modify the code to use the NewMail object. Create a comment block to include the new code so that you can see where your changes are. Now you can begin to use the various properties and methods from the NewMail object to implement the mail features.

The values you feed to the properties are pulled from the parameters passed to CreateMail when it executes. Use the statement below to set the from address:

oMail.From = sMailFrom

Set the to address with this statement:

oMail.To = g_sPageMailTo

Set the subject with this statement:

oMail.Subject = sMessageSubject

Set the message body using this statement:

oMail.Body = sMessageText

When you have set the message properties, you can use the Send method to send the email message:

oMail.Send

Finally, set the object variable that represents the CDONTS.NewMail object to Nothing, which releases the object and lets NT 4.0 destroy it, freeing its resources:

Set oMail = Nothing

The changes to the code are complete. Now, save the file. (For the complete code, see Listing 2.)

Testing WebCheck
You can step through the execution of WebCheck by pressing F5 and running the execution in the VB environment. You can also use the single-step commands on the Debug menu to step through the code one line at a time. If any errors occur, VB stops the application in Debug mode, letting you use the Debug menu commands to inspect your code. (I will cover more about using VB's Debug mode in a future article.)

Compiling the File
The last step in making the change is to compile the file. Select Make webcheck.exe from the File menu, then select the directory in which to store the executable. Make sure you don't overwrite the existing .exe file until WebCheck is working correctly. Click OK to start the compilation process. If you avoided errors in making your changes, the compilation will finish as usual, and you'll have a new webcheck.exe with your changes.

Testing the Compilation
When you've compiled WebCheck, you can use the information in my December 1999 article to test it. Test WebCheck on a test server on which you can run WebCheck with the Web server running, then shut down the Web server and run WebCheck again. You'll see email to the account you entered when the Web server wasn't running. You can also test WebCheck by pointing it at an existing page, running WebCheck, then renaming the page and running WebCheck again.

Setting Up Your Server
To deploy WebCheck, copy it to a server on which you've installed CDONTS. You need the VB runtime on the server on which you plan to run WebCheck. (If you have VB or another application written in VB installed on the server, you have the runtime.) You can execute WebCheck by double-clicking webcheck.exe or by using a scheduler service to automate it.

You can also package the new webcheck.exe file in an installation package, which will install the runtime for you along with the new executable. Visual Studio (VS) includes the Visual Studio Installer, which you can use to create the install package based on the new Windows Installer. Screen 2 shows the Visual Studio Installer. You can also repackage WebCheck with other tools such as the Visual Basic Packaging and Deployment Wizard.

Using Other NewMail Properties
You can use several other methods and properties within the NewMail object. For example, you can create a copy list for any mail by using the Cc or Bcc properties. Cc adds the name or names to a standard copy list; any recipients can see the other names on the list. The Bcc property adds the names to a blind copy list, hiding them from any other recipients. You use both these properties just like you use the To property.

To add names to the copy list, use this syntax:

oMail.CC = "kenspencer@
32x.com"

You can change the importance of a message by using the Importance property. For example, to set the importance as High, use this syntax:

oMail.Importance = CdoHigh

The CdoHigh entry in the above statement refers to a constant. The reference you created to the CDONTS library supplies this constant. You can see the values for the Importance constant in Table 1.

Extending WebCheck's Functionality
You can customize the CreateMail function by using any or all of the features I discussed in this article. When you've wired in CDONTS, the other options are available. Because WebCheck can already check the status of NT services and Web applications, you can modify it to extend this functionality. You could easily have WebCheck test all the servers in your network for particular services, Web applications, and file services.

In a future issue, I'll explore using File System Object (FSO) with Active Server Pages (ASP) and VB. I'll also discuss where you can use FSO with applications like WebCheck.

Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish