Export (0) Print
Expand All

Sending E-Mail Without Installing the SMTP Service

Microsoft® Windows® 2000 Scripting Guide

The script shown in Listing 17.23 can be used as long as the SMTP service is installed on the computer where the script is running. Obviously, this poses a problem: Most likely, you do not want the SMTP service to be installed and running on every one of your computers.

Even if the SMTP service is not installed on the computer, you can still send e-mail from a script as long as the SMTP service is installed somewhere on your network. To do this, your script must include code that specifies the properties of the computer and the SMTP service that will be used to send the message.

Each e-mail Message object has an associated Configuration object that defines configuration settings for sending the message. These settings are stored as fields within the Configuration object; each field is a Uniform Resource Identifier (URI) that contains information for the configuration setting. The three URIs required to send an SMTP e-mail message are shown in Table 17.10.

Table 17.10 Required URIs for Sending SMTP E-Mail Messages

Configuration Field

Description

SendUsing

Indicates how the message is to be sent. Values are:

1 - Send messages by using the locally installed SMTP service. Use this value if the SMTP service is installed on the computer where the script is running.

2 - Send messages by using the SMTP service on the network. Use this value if the SMTP service is not installed on the computer where the script is running.

The full name for this field is:

http://schemas.Microsoft.com/cdo/configuration/sendusing

SmtpServer

DNS name or IP address of the SMTP server through which messages are sent.

The full name for this field is:

http://schemas.Microsoft.com/cdo/configuration/smtpserver

SmtpServerPort

The port on which the SMTP server listens for connections. This is typically port 25.

The full name for this field is:

http://schemas.Microsoft.com/cdo/configuration/smtpserverport

Scripting Steps

Listing 17.24 contains a script that sends e-mail from a computer that is not running the SMTP service. 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. Specify the configuration properties for the remote SMTP server. In this script, those properties and their values are:

    • SendUsing. This property is set to 2, meaning that the SMTP service is not installed on this computer. Messages must instead be sent by using the computer specified in the SMTPServer property.

    • SMTPServer. This property is set to MySMTPHost, the name of the SMTP server on this hypothetical network. If the name of your SMTP server is MailServer1, set this property to MailServer1.

    • SMTPServerPort. This property is set to 25, the default SMTP port for most computers.

  4. Use the Send method to send the message.

Listing 17.24 Sending E-Mail Without Installing the SMTP Service

  
1
2
3
4
5
6
7
8
9
10
11
12
13
14


Set objEmail = CreateObject("CDO.Message")
objEmail.From = "admin1@fabrikam.com"
objEmail.To = "admin2@fabrikam.com"
objEmail.Subject = "Server down"
objEmail.Textbody = "Server1 is no longer accessible over the network."
objEmail.Configuration.Fields.Item _
 ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objEmail.Configuration.Fields.Item _
 ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _
"MySMTPHost"
objEmail.Configuration.Fields.Item _
 ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objEmail.Configuration.Fields.Update
objEmail.Send

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