Welcome to Professional ASP.NET - Chris Love's Official Blog Sign in | Join | Help

Chris Love's Official ASP.NET Blog

Chris Love's Helpful tips, tricks and pragmatic development knowledge for the ASP.NET world.
Add to Technorati Favorites


ASP Insider
Sending E-Mail from ASP.NET - Configuring the SMTP Server

One of the big improvements in the configuration and maintenance of ASP.NET Web sites for version 2.0 is the ability to define common settings such as connection strings and mail server in a structured section of the web.config file. I previously made an entry explaining how to send an e-mail in ASP.NET and wanted to do a quick follow up on configuring the SMTP server.

In my previous entry I stated you needed to pass the SMTP server and showed example code to this effect. This is not necessarily true in ASP.NET 2.0. While you have the flexibility to define a specific SMTP server when you send an e-mail you can use a default SMTP server defined in the site's web.config file.

  <system.net>
    <mailSettings>
      <smtp>
        <network host="SMTP.MyDomain.com"/>
      </smtp>
    </mailSettings>
  </system.net>

You can add a system.net section at any top level position in the web.config file and add a mailSettings section to it. Here you can define the SMTP server as displayed in the smtp section. The SMTPClient class will use this server by default if no SMTP server is explicitly passed to the constructor or the Host property.

Posted: Wednesday, June 27, 2007 10:23 AM

by Chris Love
Filed under: , ,

Comments

No Comments

Leave a Comment

(required) 

(required) 

(optional)

(required) 

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS