Export (0) Print
Expand All

Sending E-Mail from a Script

Microsoft® Windows® 2000 Scripting Guide

Enabling a script to send automated e-mail messages provides a way for your script to send real-time alerts whenever a particular event occurs (for example, when the script runs, when the script finishes, or when the script encounters a problem of some kind). Alerts are commonly used in system administration scripting, but these notices are typically displayed either by using pop-up message boxes or by recording an event in the event log. Although both of these techniques are useful, they require someone to either physically sit at the computer where the message box is displayed or continually monitor the event log for the occurrence of new events.

By contrast, e-mail alerts can be directed to a particular administrator or group of administrators regardless of their physical location; administrators can receive these alerts even if they are off-site. Because most administrators read their e-mail more often than they read event logs, there is a greater chance that they will respond quickly to the e-mail alert. With the new generation of PDAs and cell phones that can be used to check e-mail, the ability to programmatically send alerts using this technology becomes even more valuable.

E-mail can be sent from any Microsoft® Windows® 2000-based computer by using CDO.

Scripting Steps

Listing 17.23 contains a script that sends an e-mail message by using CDO. To carry out this task, the script must perform the following steps:

  1. Create an instance of a CDO e-mail message.

  2. Set the values for the From, To, Subject, and TextBody properties of the message.

  3. Use the Send method to send the message.

For this script to work, the SMTP service must be installed on the computer where the script is being run.

Listing 17.23 Sending E-Mail from a Script

  
1
2
3
4
5
6


Set objEmail = CreateObject("CDO.Message")
objEmail.From = "monitor1@fabrikam.com"
objEmail.To = "admin1@fabrikam.com"
objEmail.Subject = "Atl-dc-01 down"
objEmail.Textbody = "Atl-dc-01 is no longer accessible over the network."
objEmail.Send

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft