title: How to read system.net/mailSettings/smtp from Web.config
body: <p>This is my <code>web.config</code> mail settings:</p>
  
  <pre><code>&lt;system.net&gt;
      &lt;mailSettings&gt;
        &lt;smtp deliveryMethod="Network" from="smthg@smthg.net"&gt;
          &lt;network defaultCredentials="true" host="localhost" port="587" userName="smthg@smthg.net" password="123456"/&gt;
        &lt;/smtp&gt;
      &lt;/mailSettings&gt;
    &lt;/system.net&gt;
  </code></pre>
  
  <p>and here's how I try to read the values from <code>web.config</code></p>
  
  <pre><code> var smtp = new System.Net.Mail.SmtpClient();
   var credential = new System.Net.Configuration.SmtpSection().Network;
  
   string strHost = smtp.Host;
   int port = smtp.Port;
   string strUserName = credential.UserName;
   string strFromPass = credential.Password;
  </code></pre>
  
  <p>But credentials are always null. How can i access these values?</p>