Most Web sites and Web applications use some type of Internet mail feature so users can mail messages to the Web master or other individuals within an organization. To make this process easy and transparent, Microsoft has added a Simple Mail Transfer Protocol (SMTP) Mail Service to Internet Information Server (IIS) 4.0. The SMTP Service is an SMTP interface that includes everything you need to connect to a mail server. You can use it to connect to Microsoft Exchange Server or other mail servers with similar SMTP features.
After you set up the SMTP Service, you can configure and manage it according to your needs. SMTP Service also includes several tools to help you monitor and tune the server. Finally, you can take steps to secure the SMTP Service before you implement it.
Setup and Configuration
The SMTP Service is easy to set up. I was able to mail a message from a demonstration Active Server Pages (ASP) application in about 5 minutes. This performance was good considering I connected to a remote mail server in another state that I could access only over the Internet.
The first step in setting up the SMTP Service is to identify the mail server, such as Microsoft Exchange Server, that will process the mail. (For more, see Spyros Sakellariadis, "Using Microsoft Email Clients with Exchange Server," page 165.) This mail server is the smart host. To set up the smart host, start the Internet Service Manager (ISM). Right-click the Default SMTP Site to display the context menu, and select Properties to display the site properties. Select the Delivery tab, and enter the name or IP address of the smart host in the Smart host text box, as Screen 1, page 188, shows. Click Apply or OK to complete the change.
Notice the form of the smart host name in Screen 1. This entry is the valid Domain Name System (DNS) name for the smart host mail server. In this example, the SMTP Service is accessing a mail server across the Internet. If the mail server is on your network, you can enter the standard server name that you use in LAN applications such as Windows NT Explorer.
You can improve the SMTP Service's performance slightly by specifying the IP address for the smart host instead of its name. To use the IP address, enter the address for the smart host in square brackets to let IIS know that this value is an IP address. When you use the IP address, IIS skips parsing the address string to identify it.
After you configure the smart host, you can use the SMTP Service to create a mail application. To create a mail application, use the Collaboration Data Objects (CDOs) for NT Server in your ASP application. The ASP code in Listing 1, page 188, uses a CDO to send a mail message using the NewMail object.
In Listing 1, the objMail.Send statement passes the recipient's email address (firstname.lastname@example.org), the sender's email address (email@example.com), the subject line (Interest), and a variable (sBody) that contains the body of the message to the SMTP Service. The NewMail object is the easiest resource to use when composing a new message because it takes only a few lines of code. You can also use the Session object to create a session and perform advanced actions.
Managing the SMTP Service
When you install IIS 4.0, it automatically installs the SMTP Service unless you change this default. The setup process assigns the name Default SMTP Site to the server running SMTP Service. You can have only one SMTP site per SMTP server.
The SMTP Service must have a default domain. When you install the SMTP Service, the software automatically creates the default domain and gives it the same name as your server's computer name. You can use ISM to add new domains any time.
To create a new domain, choose New from the Action menu in the ISM, and select Domain (you can also right-click the right pane of the ISM, select New, and select Domain from the context menu). Select the type of domain (i.e., Local or Remote) you want to create, and enter the name for the new domain. Screen 2 shows the two domains for the Default SMTP Site in the right pane of the ISM. To access a domain's properties, select the domain and click the Properties icon.
To change the name and other properties associated with the Default SMTP Site, go to the SMTP Site tab, as you see in Screen 3. In this dialog box you can adjust server performance parameters. You can change the TCP port numbers and limit the number of connections for incoming and outgoing messages. You can also set the connection timeout, which controls the number of seconds that elapse before the server closes an inactive user connection. This setting helps you control the amount of overhead on the server by limiting these connections. You change this property in the Outgoing Connections area on the SMTP Site dialog box.
You can use the Operators tab, which Screen 4 shows, to add users who can manage the SMTP Service. By default, IIS configures only the Administrators group.
The Messages tab in Screen 5 lets you control messages that flow through the SMTP Service. To restrict the maximum message size, select the Limit Messages check box and change the values in the Maximum message size or Maximum session size text boxes. You can also limit the maximum number of outbound messages per connection and restrict the number of recipients per message in this dialog box. Screen 5 shows the default values for all these settings.
The Messages tab also contains a text box in which you can specify a mailbox to receive reports about undeliverable messages. When you enter an email address in the Send a copy of non-delivery report to text box, the SMTP Service drops a notice into the mailbox you specify, whenever the SMTP Service cannot deliver a message.
In addition to using the Delivery tab in Screen 1 to specify the smart host, you can select features on the Delivery tab to change the queue retries and time intervals. You can also change the settings related to message delivery in this dialog box.
Monitoring and Tuning the SMTP Service
The SMTP Service provides several logging features you can use to track operational details. You can combine the SMTP Service log information with the IIS Service log information, or you can track the SMTP Service log information in a separate file. You can use Open Database Connectivity (ODBC) logging to direct the log information to an ODBC target such as a database. Keep in mind that if you turn on logging, you will add overhead to the server.
To enable logging, select the properties for the Default SMTP Site, and open the SMTP Site dialog box. Select the Enable Logging check box (as Screen 3 shows), and select the log type from the Active log format list. Click Properties on the SMTP Site dialog box, and select the appropriate options to change the Extended properties.
You can monitor the number of connections for the SMTP Site by selecting the Current Sessions folder in the ISM, as Screen 2 shows. The Current Sessions folder displays all users currently connected to the SMTP server and shows how long they have been connected.
Performance Monitor can also track SMTP Service actions. The SMTP Service installs the SMTP Service object with several counters. Some of these counters measure average statistics and the local and remote queue lengths, and other counters provide more detailed information about the SMTP server.
The SMTP Service documentation suggests that you monitor the Local Queue and Remote Queue counters. If either counter exceeds zero, the server is receiving more messages than it can process.
You can tune the SMTP Service in several ways. You can specify the IP address for the smart host instead of using the server name, and you can limit the number of concurrent connections to the SMTP server to control the server load, as I mentioned previously. You can also set the maximum number of outbound messages per connection in the Messages dialog box to further tune the performance.
Another performance option lets you control any single remote domain. You set this property in the Outgoing Connections area of the SMTP Site dialog box to control the maximum load that one domain can place on the server.
The SMTP Service can use Transport Layer Security (TLS) to encrypt mail messages before sending them to the mail server. You can configure TLS for the entire SMTP Service or for each domain. Before you set up TLS, you must install a certificate from a Certificate Authority such as VeriSign (http://www.verisign.com).
To enable TLS and encrypt messages for the SMTP Service, select the properties for the Default SMTP Site and select the Directory Security tab. Under Secure Communication, select the Edit option and select the Require Secure Channel check box. To enable TLS for a specific domain when sending outgoing messages, display the domain's properties, click Outbound Security and select the TLS encryption check box.
Other security options you can use include assigning specific SMTP operators, and setting the authentication level for the SMTP Service. You can also change the authentication level for each domain.
IIS 4.0's SMTP Service is a powerful new feature. Now you can perform messaging-related functions without purchasing a separate mail component for the site. This built-in functionality makes setting up messaging easier and provides you with a reliable upgrade path as Microsoft enhances the mail features of IIS.