System.Net.Mail FAQ

Complete FAQ Listing


4.1 How do I read SMTP configuration data? Printer Friendly

Using special settings in your app's configuration file, System.Net.Mail can configure itself.

Using the configuation file, you can set the following default properties:

MailMessage.From
SmtpClient.Host
SmtpClient.Port
 

The settings will also allow you specify a Username and Password to be used for authentication. It is important to note that if DefaultCredentials are specified to true, the userName and password attributes are igorned.

Here is an example of the  <mailSettings> node:

 

<configuration>
  <system.net>
    <mailSettings>
      <smtp from="me@mycompany.com">
        <!--
            The <network> node supports the following properties, but we won't use all of them
            <network host="127.0.0.1" port="25" userName="myUserName" password="secret" defaultCredentials="true" />
        --
>
        <network host="127.0.0.1" />
       </
smtp>
    </
mailSettings>
   </
system.net>
</configuration>