Export (0) Print
Expand All

Sending E-Mail

Microsoft® Windows® 2000 Scripting Guide

E-mail is one of the most important avenues of communication within large organizations, and for good reason. E-mail is not dependent on time or place; messages can be sent at any time of the day or night, and they can be accessed from practically anywhere. The fact that it might be after hours or that you do not know the physical location of the recipient is no deterrent to sending information via e-mail.

For that matter, the fact that no human being is present is also no deterrent to sending information via e-mail. You can include code that enables your scripts to send e-mail in response to a specified event. For example, a monitoring script can be coded so that it sends an e-mail message anytime disk space begins to run low on a server. An inventory script can retrieve information and then, instead of saving that information to a file, e-mail it to the appropriate administrator.

You can use the Collaboration Data Objects (CDO) technology to incorporate e-mail messaging within a script. CDO includes a COM component (Cdosys.dll) that can be used to send e-mail messages by using either the SMTP or the NNTP protocol. These messages can be sent even if the SMTP or NNTP service is not installed locally; you can use CDO to send messages as long as the SMTP or NNTP service is installed somewhere on your network.

The CDO automation library defines a number of objects, including the Message object, which represents a complete e-mail message. In turn, the Message object has a number of interfaces, including the IMessage interface. This interface is used to perform such tasks as addressing, adding content to, and sending a message.

Some of the key properties of the IMessage interface are shown in Table 17.9.

Table 17.9 IMessage Interface Properties

Property/Method

Description

AddAttachment

Enables you to add an attached file to the message. As the AddAttachment parameter, specify the full path name of the file to be attached.

From

E-mail address of the primary author of the message. This property is optional; if left blank, the From property will be set to the value of the Sender property, assuming a value for this property has been configured. If neither the From property nor the Sender property is configured, the script will fail.

ReplyTo

E-mail address or addresses that replies should be sent to.

Sender

E-mail address of the person who actually sent the message. This does not have to be the same address as the From property. If the From and Sender properties refer to the same person, you do not need to configure the Sender property.

Subject

Specifies the subject line for the e-mail message.

TextBody

Plain-text representation of the actual e-mail message.

To

Specifies recipients of the message.

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