Sending Email Notifications


When you need to send email from the command line, calling Collaboration Data Objects (CDO) from a VBScript can be the solution. For Windows NT 4.0 servers, you can use an earlier version of the CDO interface, Collaboration Data Objects for Windows NT Server (CDONTS). CDONTS is available with Microsoft Internet Information Server (IIS) 4.0, Microsoft Commercial Internet System (MCIS), and Exchange Server 5.5’s Internet Mail Connector (IMC). CDO for Windows 2000 (CDOSYS) is an integral part of the Win2K Server OS.

Unfortunately, CDOSYS isn't code-compatible with CDONTS, so the VBScript you use depends on your OS. Listing A provides a sample script that uses CDONTS to send an SMTP message; Listing B provides a sample script that uses CDOSYS. Copy the code into a new text file, then rename the file with a .vbs extension. Please note that for clarity's sake, these examples omit error-checking and reporting code. Your production code should check for and report errors.

The script that uses CDONTS is amazingly simple. The script that uses CDOSYS is a bit more challenging, primarily because of the new interface’s extended functionality. IIS, MCIS, and the IMC provide an SMTP service on an NT 4.0 server. SMTP is likely to be available on generic Win2K installations (Win2K provides SMTP as part of its built-in IIS component), to attach to an SMTP server to send messages through. Therefore, the value of cdoSendUsingMethod in Listing B varies depending on whether the SMTP service is installed. The value defaults to 1 if SMTP is installed or to 2 if it isn’t.

The scripts in Listing A and Listing B offer limited functionality, but you can produce numerous variations. For example, the code in Listing C includes in the message text the name of the server that’s producing the error. (For NT 4.0 systems, you need to download and install Windows Script Host—WSH—from the Microsoft Web site before you run the script.)

Hide 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.