How do I properly setup IIS5's SMTP service to send email from my development environment?

JimJ picture JimJ · Jan 16, 2009 · Viewed 7.3k times · Source

I am trying to send email from an ASP.NET web application using the SmtpClient class. So far I have granted relay access to 127.0.0.1. I am trying to send test emails to my gmail account. The EML files get stuck in the mailroot's queue folder. My WinXP firewall is disabled. I dont get any exceptions in the code but the emails are never delivered to the destination address. I also tried other email accounts.

        SmtpClient client = new SmtpClient();
        client.Host = "127.0.0.1";

        MailMessage message = new MailMessage();
        message.To.Add("[email protected]");
        message.From = "[email protected]";
        message.Subject = subject;
        message.IsBodyHtml = false;
        message.Body = body;

        client.Send(message);

Here is a snippet from the IIS SMTP log.

Software: Microsoft Internet Information Services 5.1
Version: 1.0
Date: 2009-01-16 18:28:28
Fields: time c-ip cs-method cs-uri-stem sc-status 
18:28:28 127.0.0.1 EHLO - 250
18:28:28 127.0.0.1 MAIL - 250
18:28:28 127.0.0.1 RCPT - 250
18:28:28 127.0.0.1 DATA - 250
18:29:45 127.0.0.1 MAIL - 250
18:29:45 127.0.0.1 RCPT - 250
18:29:45 127.0.0.1 DATA - 250
18:30:37 127.0.0.1 QUIT - 0

Answer

PhilPursglove picture PhilPursglove · Jan 20, 2009

Depending on how your network is set up, you might need to tell IIS to pass on emails to your Exchange server to be passed on to the outside world. To do this:
1. Right-click on the Default SMTP Virtual Server node in the IIS MMC Snap-in and open the Properties dialog.
2. Go to the Delivery tab and click on the Advanced button at the bottom of the tab.
3. In the Smart Host box, enter the name of your Exchange server. (Or a DNS entry for the same e.g. smtp.mydomain.com)