Monday, August 18, 2008

Sending Email in ASP.NET 2.0

Coincidentally for the 3rd time in the past week an issue I was working on led me to an article written by Scott Mitchell.
 
 
"The relay server information used by the SmtpClient class can be specified programmatically, through the SmtpClient class's properties, or can be centralized in Web.config. To use the Web.config approach, add a <system.net> element within the <configuration> element. Then, add a <mailSettings> element that contains an <smtp> element whose settings are specified within its <network> child element, like so:"
 
<configuration>
     <!--
Add the email settings to the <system.net> element
-->
     <
system.net
>
          <
mailSettings
>
               <
smtp
>
                   
<
network
                        
host="relayServerHostname"
                         port="portNumber"
                         userName="username"
                         password="password"
/>
               </
smtp
>
          </
mailSettings
>
     </
system.net
>

     <
system.web
>
          ...
     </system.web
>
</
configuration>
 
Scott Mitchell is the the editor, founder, and primary contributor to 4GuysFromRolla.com.

0 comments: