title: SMTP email not working in ASP.NET7 + II7, but working in Telnet
body: <p>Basically, we bought a new server with <strong>Windows Server 2008 R2, IIS 7.5</strong> and have set up an SMTP server. There are no special settings. The code used was working fine in <strong>Windows Server 2003, IIS6</strong>.</p>
  
  <p>Here is a summary of the settings</p>
  
  <ol>
  <li>port 25, all unassigned</li>
  <li>Anonymous Access</li>
  <li>127.0.0.1 is granted to relay access</li>
  <li>Anonymous Access set for outbound
  security.</li>
  </ol>
  
  <p>I can send an email via <strong>telnet 127.0.0.1 25</strong></p>
  
  <p>The problem is I can't sent emails through a send a friend Asp.Net page.</p>
  
  <p>For the ASP.NET SMTP Email in IIS7, here are my settings</p>
  
  <ol>
  <li>Deliver email to SMTP Server:
  <strong>127.0.0.1, port 25</strong></li>
  <li>Authentication Settings: <strong>Not Required</strong></li>
  </ol>
  
  <p>In my web.config, I have the following:</p>
  
  <pre><code>&lt;system.net&gt;
    &lt;mailSettings&gt;
      &lt;smtp&gt;
        &lt;network host="127.0.0.1" port="25" /&gt;
      &lt;/smtp&gt;
    &lt;/mailSettings&gt;
  &lt;/system.net&gt;
  </code></pre>
  
  <p>Here is the code-behind code:</p>
  
  <pre><code>MailMessage M = new MailMessage();
  M.Subject = subject;
  .To.Add(new MailAddress(e1, f1));
  M.From = new MailAddress(sendemail, sendname);
  M.ReplyTo = new MailAddress(sendemail, sendname);
  M.IsBodyHtml = true;
  M.Body = email_message;
  
  SmtpClient sClient = new SmtpClient();
  sClient.Send(M);
  </code></pre>
  
  <p>Here is the event log info:</p>
  
  <p>Process information: 
      Process ID: 2840 
      Process name: w3wp.exe 
      Account name: NT AUTHORITY\NETWORK SERVICE </p>
  
  <p>Exception information: </p>
  
  <ul>
  <li>Exception type: WebException</li>
  <li>Exception message: Unable to connect
  to the remote server</li>
  </ul>
  
  <p>Request information: </p>
  
  <ul>
  <li>Request URL: ...</li>
  <li>Request path: ...</li>
  <li>User host address: ...</li>
  <li>User:</li>
  <li>Is authenticated: False</li>
  <li>Authentication Type:</li>
  <li>Thread account name: NT
  AUTHORITY\NETWORK SERVICE</li>
  </ul>
  
  <p>Any ideas on why I can send email through telnet but not an asp.net page?
  Again, this send a friend aspx page was working fine in Windows Server 2003.</p>
  
  <p>I also referenced this page, <a href="http://forums.iis.net/t/1157046.aspx" rel="nofollow noreferrer">http://forums.iis.net/t/1157046.aspx</a> and am wondering what I am missing.
  Thanks!</p>