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.

        <network host=""/>

You can add a 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.

Share This Article With Your Friends!

We use cookies to give you the best experience possible. By continuing, we'll assume you're cool with our cookie policy.

Install Love2Dev for quick, easy access from your homescreen or start menu.

Googles Ads Facebook Pixel Bing Pixel LinkedIn Pixel