Configuring an E-Mail Server


When you send e-mail from a Web application, you re not really sending the e-mail directly from your application to the recipient. Instead, you send the e-mail message from your application to an e-mail server. The e-mail server in turn performs the low-level tasks required to look up the recipient s e-mail address and send the message on its way to the recipient s mailbox.

To send e-mail messages from your Web pages, therefore, you ll need an e-mail server. Microsoft offers a commercial-level e-mail server product named Microsoft Exchange Server, but you (like most individual users) probably don t have Exchange Server running on your computer. Even if you don t have Exchange Server or a similar product from another vendor running on your computer, you can still set up an e-mail server. Our old friend Internet Information Services (IIS), which we normally think of as a Web server, actually includes facilities for a variety of services (hence its name). One of these services is the Simple Mail Transfer Protocol (SMTP) virtual server. The SMTP virtual server can act as your private e-mail server, accepting and forwarding e-mail messages that you create in your Web applications.

How the SMTP Virtual Server Works

The SMTP virtual server in IIS and the IIS Web server work in similar ways. Like the Web server, the SMTP server runs as a Microsoft Windows service. When you send an e-mail message from a Web page, the e-mail message is deposited into a special folder under the mailroot directory of your computer. The mailroot directory is usually under the inetpub folder. The SMTP server continually monitors this special folder. When the SMTP server detects a message in the folder, the server reads the message, parses the message to find the recipient information, and then sends the e- mail message on its way to the recipient s e-mail server (the server name that follows the @ in the recipient s e-mail address). The process of sending an e-mail message is illustrated in Figure 15-1.

click to expand
Figure 15-1: An SMTP virtual server monitors for e-mail messages and forwards them to the recipient s e-mail server.

Installing and Configuring the SMTP Virtual Server

To send e-mail messages from Web applications running on your computer, you need to have the IIS SMTP virtual server installed. The IIS SMTP virtual server is probably already installed on your computer. Let s check.

Check for the SMTP virtual server

  1. In the Windows Control Panel, and in Administrative Tools, open the Internet Information Services window.

  2. Open the node for your computer, and check for the Default SMTP Virtual Server node. If you see that node, the SMTP virtual server is installed and you can send e-mail messages from your Web applications.

If the SMTP server is installed, you can skip the procedure for installing the SMTP virtual server and go on to the procedure for configuring the SMTP server. If you didn t see the Default SMTP Virtual Server node, the SMTP virtual server isn t installed, so let s install it next. To install the IIS SMTP virtual server, you ll need your Windows installation CD.

Install the SMTP virtual server

  1. Open the Windows Control Panel, and choose Add Or Remove Programs.

  2. In the Add Or Remove Programs dialog box, select the Add/Remove Windows Components option. Selecting this option displays the Windows Components Wizard.

  3. Select Internet Information Services (IIS), and then click the Details button.

  4. In the Internet Information Services (IIS) window, check SMTP Service, and then click OK to return to the wizard.

  5. Click Next. Windows will prompt you to insert your Windows installation CD into the CD drive. The wizard will get the files it needs and finish installing the SMTP virtual server.

    Tip 

    If inserting the CD causes the Windows installation program to start running, you can close that program. Closing the automatic Window installation program won t affect the component installation wizard.

Once the SMTP virtual server is installed, you need to configure the server to restrict who can relay e-mail messages through the server. For details about the following procedure and about security for the SMTP server generally, see the sidebar Securing Your SMTP Server.

Configure the SMTP virtual server

  1. In the Windows Control Panel, choose Administrative Tools, and then choose Internet Information Services.

  2. In the Internet Information Services window, open the node for your computer.

  3. Right-click the Default SMTP Virtual Server node, and choose Properties.

  4. Click the Access tab, and then click the Relay button. The Relay Restrictions dialog box is displayed, as shown here:

    click to expand

Make sure that the Only The List Below option button is selected.

  • Click the Add button to open the Computer dialog box. Under IP address, type 127.0.0.1, which is the IP address reserved for your local computer, as shown here:

    click to expand

  • Click OK to close the Computer dialog box.

  • Uncheck the Allow All Computers Which Successfully Authenticate To Relay, Regardless Of The List Above check box.

  • Click OK to close the Relay Restrictions dialog box and the Properties window.

  • Note 

    If your computer is part of a local area network (LAN), you might need to make further configuration changes to the SMTP virtual server. For example, computers on a LAN often can t send e-mail messages directly via their local SMTP server; instead, individual LAN computers send e-mail messages to a computer on the network specifically configured to send e-mail (a smart host computer). In general, you should ask your network administrator whether your SMTP virtual server has any special configuration requirements.

    You ve now finished installing and configuring the IIS SMTP virtual server. If the hard disk in your computer uses the NTFS filing system, one configuration task remains, which is to set Windows permissions on an executable file that performs some of the work of sending e-mail. If the hard disk is configured to use the FAT filing system, you don t need to perform the following procedure. If you re not sure which filing system you re using, try the procedure; you ll be able to tell during the procedure which filing system you re using.

    Set Windows permissions to send e-mail messages

    1. In Windows Explorer, navigate to the System32 directory of your computer. This is typically in the path C:\Windows\System32 or C:\Winnt\System32, but your computer might have the System32 directory in a different location.

    2. In the directory, right-click the file cdosys.dll, and choose Properties. The cdosys.dll file contains the low-level code that will be called when you send e-mail messages.

    3. Click the Security tab, shown here:

      click to expand

    Note 

    If you don t see the Security tab, your hard disk is not configured for the NTFS system. If your hard disk is configured with the FAT filing system, you can t set security options for the file, so you don t need to finish this procedure.

  • Click Add, and then add the user name <yourcomputername>\ASPNET. For example, if your computer is named MyTestComputer, you would add the user name MyTestComputer\ASPNET.

  • Click the Check Names button. Windows fills in the name you specified in the previous step, as shown here:

    click to expand

    Your applications run under the ASPNET account, so the account needs access to certain resources of your computer, such as the cdosys.dll file. I ll explain the ASPNET account in more detail in Appendix A.

  • Click OK to return to the cdosys.dll Properties window.

  • Make sure that only the Read & Execute and Read check boxes are checked, as shown here:

    click to expand

  • Click OK.

  • You re now configured properly to send e-mail messages from Web applications running on your computer. With that out of the way, it s time to have some fun and create a page that you can use to compose and send e-mail messages. However, before you create a page to send e-mail messages, make sure you understand the security implications of running an SMTP virtual server on your computer.

    start sidebar
    Securing Your SMTP Server

    As with running a Web server, running an SMTP virtual server on your computer raises some familiar security issues. The primary security threat to an SMTP server is that people might be able to find your server and take advantage of it to relay (forward) e-mail messages for them. Relaying e-mail messages using someone else s SMTP server is a favorite trick of spammers. If spammers can find your SMTP server and use it to relay e-mail messages, the e-mail messages they forward look like they ve come from you. Moreover, the e-mail message that a spammer relays through your SMTP server can contain thousands of recipients, which can put a huge load on your computer s resources as it sends the message to each recipient. If you have an unsecured SMTP server, spammers can not only steal your computer s identity as the source of unwanted e-mail, but also steal your bandwidth.

    Spammers can take advantage of an SMTP server like yours because the SMTP server by default doesn t check who is asking it to send the e-mail message. The server simply monitors e-mail requests, and when it receives a request, the server forwards the e-mail message. This process is similar to the way the Web server monitors Web page requests the Web server also doesn t discriminate between requests from you and requests from others. You can prevent your SMTP server from being used to relay unwanted e-mail messages by configuring the SMTP server to accept e-mail requests only from your computer, as you did in the section Installing and Configuring the SMTP Virtual Server. To be doubly sure that spammers don t relay messages using your SMTP virtual server, you can configure your firewall so that it doesn t accept any external requests for e-mail relaying. I discuss firewalls in more detail in Appendix A.

    If you re not running an SMTP server on your computer and will run your Web pages only on a hosting site, you should either stop your SMTP virtual server or uninstall it altogether. Stopping or uninstalling the SMTP server will ensure that no one can use it in ways that you don t intend.

    end sidebar



    Microsoft ASP. NET Web Matrix Starter Kit
    Microsoft ASP.NET Web Matrix Starter Kit (Bpg-Other)
    ISBN: 0735618569
    EAN: 2147483647
    Year: 2003
    Pages: 169
    Authors: Mike Pope
    BUY ON AMAZON

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net