Friday, November 24, 2006

How to configure the IIS SMTP Service to send emails from ASP.NET code?

I have probably configured the IIS SMTP service a dozen times over the past five years but I still struggle with authentication and relay, so I have decided to write this note once and for all.

First, the source for your System.Net.Mail issues is definitely, including some sample code.

Because we are all urged to deliver rapidly, I have provided a test application which you can download from Contrary to most samples that you will find on the Internet, this one uses a configuration file including\mailSettings, which is probably the way you want to send emails from your ASP.NET code.

Obviously you need to install the SMTP Service, which is well explained at

Let’s say you need to send your emails from website@yourdomain.tld. In this case, it is recommended (but not required) that you rename the default domain into yourdomain.tld.

Display the default SMTP Virtual Server properties and on the Access tab:

  1. Configure authentication by removing Anonymous access and allowing Basic authentication and/or integrated Windows authentication;
  2. Grant relay to and allow all computers which successfully authenticate to relay.

You can certainly be more restrictive depending on your requirements, once you got teh above configuration to work properly.

Finally, you can create a dedicated account and properly configure your settings:

<smtp deliveryMethod="Network" from="website@yourdomain.tld">
<network host="" port="25" userName="DOMAIN\account" password="password"/>

No comments: