Using SMTP for Outgoing Messages
Duwamish Online
Summary: This article discusses the advantages of using the Simple Mail Transfer Protocol (SMTP) service provided by Internet Information Services (IIS) for delivering outgoing e-mail messages. It also examines the configuration and testing of the service for Duwamish Online. (7 printed pages)
![*](http://www.microsoft.com/library/gallery/templates/MNP2.Common/images/3squares.gif)
On This Page
![]() | Introduction |
![]() | How Does SMTP Work? |
![]() | Setting Up SMTP in Windows 2000 |
![]() | Conclusion |
Introduction
The Duwamish Online application sends e-mail to customers as notification of order status and to operations team members to help them monitor the health of the application. The application uses the Simple Mail Transfer Protocol (SMTP) service provided by Internet Information Services (IIS) in Microsoft® Windows® 2000. This is because application messaging requirements are easily handled by SMTP and warrant using either the external e-mail server provided by our Internet service provider (ISP), the Information Technology Group at Microsoft, or our own e-mail server, using a full-featured messaging system (such as Microsoft® Exchange Server).
While a full-featured messaging system can provide comprehensive services for processing both incoming and outgoing e-mail messages, the SMTP service in Windows 2000 is considered a more cost-effective solution (it comes free with the operating system) for sites that use e-mail for outgoing messages only.
In this article, we'll cover SMTP service configuration and testing for DuwamishOnline.com. First, however, we'll provide a brief explanation of how SMTP works.
How Does SMTP Work?
Simple Mail Transfer Protocol is one of the core Internet Protocols (IPs) designed to transfer e-mail reliably and efficiently.
The idea behind SMTP is relatively simple. A user or application (in this case Duwamish Online) composes a message containing the recipient e-mail address (for example, "johndoe@somecompany.com") along with the subject and content of the message.
Delivery of the message is initiated by transferring the message to a designated SMTP server. Based on the domain name of the recipient e-mail address (for example, "somecompany.com"), the SMTP server initiates communications with a Domain Name System (DNS) server, which looks up and returns the host name of the destination SMTP server (for example, "mail.somecompany.com") for that domain.
Finally, the originating SMTP server communicates with the destination SMTP server directly through Transmission Control Protocol/Internet Protocol (TCP/IP) port 25. If the user name of the recipient e-mail address matches one of the authorized user accounts in the destination server, the original e-mail message will eventually be transferred to that server, waiting for the recipient to pick up the message through a client program.
In the case where the originating SMTP server cannot communicate directly with the destination server, the SMTP protocol provides mechanisms to transfer messages through one or more intermediate relay SMTP servers. A relay server will receive the original message and then attempt to deliver it to the destination server or redirect it to another relay server. This process will be repeated until the message is delivered or a designated timeout period passes.
Setting Up SMTP in Windows 2000
Beginning with previous versions of Microsoft Windows NT®, the SMTP service has been implemented as one of the Internet Information Services. Because the SMTP service is mainly used in Duwamish Online to handle a relatively low volume of outgoing e-mail messages for order confirmations, there is no need to dedicate a computer for this function at the initial stage of our business. As a result, we decided to piggyback the SMTP service onto the order processing server, which already has a connection to the external Internet network segment.
To follow are the procedures we used to set up the SMTP service for the Duwamish Online Web site.
Installing the SMTP Service
To install the SMTP service
1. | From the Start menu, point to Settings / Control Panel. Double-click Add/Remove Programs, click Add/Remove Windows Components, and then click the Components button. |
2. | In the Windows Components Wizard, select Internet Information Services (IIS), and then click Details. Select the SMTP Service component and click OK. |
Note: Several other IIS components are required to support the SMTP service. They are the Internet Information Services Snap-In, World Wide Web Server, and Common Files components. These components are automatically selected and installed along with the SMTP Service component.
Configuring the SMTP Service
If the SMTP service is installed on a host computer with a network connection to the Internet, and the Internet-facing firewall is not blocking port 25 for SMTP traffic, the default settings of the SMTP service should be ready to deliver any outgoing e-mail messages. However, there are still a couple of security settings you might want to consider for your SMTP server. You can change most of these settings through the Internet Services Manager management console.
To start the IIS management console
1. | From the Start menu, point to Programs / Administrative Tools. |
2. | Click Internet Services Manager to initiate the management console. |
To set up server logging
1. | From the left pane of the Internet Information Services dialog box, expand the directory tree. Right-click the Default SMTP Virtual Server and select Properties. |
2. | In the Properties dialog box, click the General tab. Select the check box to enable logging for the server. This property is not enabled by default. |
3. | Select your preferred log file format. The default setting is W3C Extended Log File Format. |
4. | Click the Properties button next to the log file format drop-down menu. |
5. | Adjust the time schedule and file name for log file rollover, if needed. |
6. | Click the Extended Properties tab. |
7. | Select any items of interest and click OK. |
Note: To limit the size of the log file, you should not select too many of these items. Here are some suggested items that might be useful: Date, Time, Client IP Address, User Name, Service Name, Method, Bytes Sent, and Bytes Received.
To set up access control
1. | In the Properties dialog box, click the Access tab. Click the Relay button to control which computer(s) can relay e-mail messages to the SMTP server. |
2. | In the Relay Restrictions dialog box, click Add. |
3. | In the Computer dialog box, enter the IP address of the computer allowed to relay e-mail through the SMTP server. Click OK to apply the changes. |
Note: If an outgoing message is sent to the SMTP server from the same machine, the default settings of the Relay permission will work fine. However, if the message is sent from another machine, you will need to add the IP address or domain name of the other machine to the permission list to make Relay work.
Specifying smart host for relay
If your SMTP server is behind a firewall that blocks any direct SMTP traffic (through port 25), you'll need to find out if there is a smart host available on your network that is allowed to relay all SMTP messages to the Internet.
Basically, a smart host can be just another SMTP server with the permissions to relay outgoing e-mail messages, from other internal SMTP servers, directly to the Internet. As a result, a smart host should be able to simultaneously connect to both the internal network and the Internet in order to work as the e-mail gateway.
Once you have identified a smart host on your network, you can set up the SMTP server.
To set up the SMTP server
1. | In the Properties dialog box, click the Delivery tab, and then click the Advanced button to open the Advanced Delivery dialog box. |
2. | In the Smart host field, type in the fully qualified domain name (FQDN) of the smart host. Or, you can enter the IP address of the smart host, with [ and ], such as "[10.10.10.1]", around the IP address. The [] will help to speed up the DNS lookup process. |
3. | Click OK to complete the changes. |
Verifying the SMTP Service
There are a couple of ways to verify if the SMTP service is working properly.
Testing with an e-mail client
First, you can choose to use a standard Internet e-mail client program, such as Microsoft Outlook® Express, for a quick verification. Locate the place where you can specify the outgoing e-mail (SMTP) server and change it to the domain name of the new SMTP server. Send a test message to your regular e-mail address and verify its delivery.
Testing with the Pickup directory
Or, you can compose a simple e-mail text file based on the SMTP specifications (RFC 822). Here is the content of a sample text file typed in Notepad:
From: myname@mydomain.com To: someone@somedomain.com Subject: testing This is the test message body.
Simply copy or move the text file into the Pickup directory where SMTP was installed. (The default path should be "root:/Inetpub/mailroot/Pickup".) The SMTP service periodically checks into the Pickup directory and will attempt to deliver any of the messages found in the directory. Verify if you can receive the test message from the destination mailbox.
For more information about the RFC 822 specification for a properly formatted message, refer to The RFC 822 Message Format at http://msdn.microsoft.com/library/psdk/cdosys/_cdosys_the_rfc_822_message_format.htm.
Testing with CDO
Another way to verify the SMTP service is to write simple Microsoft Visual Basic® Scripting Edition (VBScript) script using Collaboration Data Objects (CDO) for Windows 2000.
CDO for Windows 2000 (a.k.a. CDO 2.0 or Cdosys.dll) is a suite of collaborative components designed to simplify the creation or manipulation of Internet messages. Instead of writing their own code for SMTP communications, developers can use CDO to send and receive messages using SMTP protocols as well as through the local Pickup directory. For more information, please refer to the related articles About CDO for Windows 2000 at http://msdn.microsoft.com/library/psdk/cdosys/_cdosys_about_cdo_for_windows_2000.htm.
Here is a VBScript example of how CDO can be used to deliver a message through the SMTP service:
set msg = WScript.CreateObject("CDO.Message") msg.From = "myname@mydomain.com" msg.To = "someone@somedomain.com" msg.Subject = "testing" msg.TextBody = "This is a test message body." msg.Configuration.Fields("http://schemas.microsoft.com/ cdo/configuration/smtpserver") = "smtpserver.mydomain.com" msg.Configuration.Fields("http://schemas.microsoft.com/ cdo/configuration/sendusing") = 2 msg.Configuration.Fields.Update msg.Send
The first five lines of the preceding code example create the CDO object and specify the basic information for the message.
The next two lines of code use the CDO Configuration object to set up field values for various configuration settings. Each field is comprised of two parts: a namespace prefix (such as "http://schemas.microsoft.com/cdo/configuration/") and a local name (such as "smtpserver").
This mechanism is based on the World Wide Web Consortium (W3C) Namespaces in XML recommendation (http://www.w3c.org/TR/REC-xml-names/) and is used primarily to provide uniformity and forward compatibility with other related versions of CDO components.
The field "smtpserver" specifies the domain name (or IP address) of the SMTP server, while the field "sendusing" defines whether to send the message using the local SMTP service drop directory, or to an SMTP server directly over the network. The latter field is set to a value of 2, meant to send the message to the designated SMTP server over the network.
Finally, the last two lines of code update the configuration settings and initiate the delivery of the message.
This method of using CDO components might be excessive for verifying the SMTP service. However, the script proves to be useful for other system administrative tasks. For example, the script can be utilized within the Performance Logs and Alerts program for e-mail notification when certain system counters go beyond their designated thresholds.
Identifying failed delivery
If an e-mail message cannot be delivered for whatever reason (for example, wrong user name or e-mail address), it will be redirected to the Badmail directory. By default, the location of the Badmail directory should be in "root:/Inetpub/mailroot/Badmail". Examine the content of the rejected e-mail and look for any specific error messages. Correct the errors, if possible, and re-send the message again through one of the delivery methods just discussed.
Besides the Badmail directory, an e-mail message can also be held in the Queue directory for a designated period of time. (This setting can be specified by adjusting the outbound retry intervals in the Delivery tab of the Default SMTP Virtual Server Properties dialog box.) If a message cannot be delivered immediately because the network connection is busy or down, the message is stored in this Queue directory and sent again at designated intervals. If SMTP gives up after several unsuccessful delivery attempts, the message will eventually be moved to the Badmail directory.