Reference

Local SMTP Mail Relay with IIS 6.0

Allow your IIS hosted web sites to send emails via local SMTP relays.

Tags: iis email server smtp windows

Overview

Some of the websites hosted on a local computer or home server may require an email server to send out emails. For example, blogs or forums may send out notifications, or personal homepages may provide a contact form. When a local mail server is not available or not desired, a local SMTP relay may be a convenient option to collect and send emails from these websites.

The relay server receives the email from the website scripts and forwards it to a pre-configured email server on your network or the internet. Instead of configuring each individual website to send emails to the outgoing email server of, say, a Gmail or Yahoo account, all emails are simply sent to localhost. This has the advantage that, if the actual remote server changes for whatever reason, only the relay needs to be updated and the website scripts remain untouched.

Installing SMTP Server

IIS already comes with a built-in SMTP server that can be configured to act as a relay. The server is not automatically installed with IIS, but it can easily be added by performing the following steps:

  1. Open Add or Remove Programs from the Control Panel
  2. Click on the Add/Remove Windows Components button on the left
  3. In the Windows Components Wizard, double-click the entry for Application Server
  4. Double-click the entry for Internet Information Services
  5. Check the box for SMTP Service
  6. Click OK, OK again, and Next > to install the component
  7. Wait while setup configures the components
  8. Click Finish when components wizard is done.

The IIS SMTP Service is now installed and ready to be configured.

Configuring SMTP Server

The next step is to configure the SMTP server as a relay. This can be done by performing the following steps:

  1. Start IIS Manager
  2. Open Properties for the Default SMTP Virtual Server node
  3. Select the Access tab
  4. Click the Authentication… button
  5. Check the boxes for Anonymous access and Integrated Windows Authentication (if you have particular authentication requirements, you can configure these here as well)
  6. Click the Relay… button
  7. Uncheck Allow all computers which successfully authenticate… (if you wish to allow computers other than localhost access to the relay, you can configure these here)
  8. Select the Only the list below radio box and click the Add… button
  9. Enter 127.0.0.1 (for localhost) and click OK
  10. Click OK to close the Relay Restrictions window
  11. Select the Delivery tab
  12. Click the Outbound Security… button
  13. Configure the user name and password for your outgoing email server and click OK (this is where the user name and password for the remote email server account goes, i.e. Gmail or Yahoo)
  14. Back on the Delivery tab, click Advanced…, enter the domain name of your email server in the Smart host field and click OK (this is the domain of the remote email server, i.e. smtp.gmail.com)
  15. Click Apply and OK to close the Properties window.

The SMTP relay is now fully operational. All emails sent to localhost on port 25 should be forwarded to the configured remote email server.

Notes on PHP

If you use PHP for some of your websites you can configure a default SMTP server to be used for the mail() function by doing the following:

  1. Open the server’s php.ini in a text editor
  2. Scroll down to the section [mail function]
  3. Enter SMTP = localhost and smtp_port = 25
  4. Save and close the file
  5. Restart the World Wide Web Publishing Service