<mailSettings> Element (Network Settings)

Configures mail sending options.

<configuration> Element
  <system.Net> Element (Network Settings)
    <mailSettings> Element (Network Settings)
<mailSettings
  <smtp> … </smtp>
/mailsettings>
Attributes and Elements

The following sections describe attributes, child elements, and parent elements.

Attributes

None.

Child Elements

Attribute

Description

<smtp> Element (Network Settings)

Configures Simple Mail Transport Protocol options.

Parent Elements

Element

Description

<system.Net> Element (Network Settings)

Contains settings that specify how the .NET Framework connects to the network.

Example

The following code example specifies the appropriate SMTP parameters to send e-mail using the default network credentials.

<configuration>
  <system.net>
    <mailSettings>
      <smtp deliveryMethod="network">
        <network
          host="localhost"
          port="25"
          defaultCredentials="true"
        />
      </smtp>
    </mailSettings>
  </system.net>
</configuration>
See Also

Reference

Tags :


Community Content

Thomas Lee
Error in example code...
This should be deliveryMethod="Network" (capitalisation on Network), raises a warning otherwise...

[tfl - 5 July 2008] - good catch, tagged as contentbug
Tags : contentbug

Andy Ballantine
Article could also have more information
Also some more information on possible configurable settings would be very useful, e.g. is it possible to specify some specific credentials to use? Might be being blind but I can't seem to find the syntax anywhere. On http://msdn.microsoft.com/en-us/library/system.net.mail.smtpclient.credentials.aspx it states:

"Credentials information can also be specified using the application and machine configuration files. For more information, see <mailSettings> Element (Network Settings)."

Well, I can't see how from this page...
Tags :

theairdog
Poor example
And what if I don't want to use the default credentials?
Tags :

Pakana
Bypass Default Credentials Programmatically

VB.NET:

Imports System.Net
Imports System.Net.Mail
Dim emailClient As New SmtpClient("Your.SMTP.Server")
Dim mycredentials As New NetworkCredential("Your_SMTP_Login", "Your_SMTP_Password")
emailClient.UseDefaultCredentials = False
emailClient.Credentials = mycredentials

a_trash
Very poor example
What about the username and password in the web.config? What if I don't want to bypass the default credentials programatically? POOR, POOR EXAMPLE.
Tags :

Tibor19
If you don't want default credentials...
Just change to defaultCredentials="false".
If you want a username and password on your web.config, just add the info as attributes for the network element:
userName="your_username" password="your_password"
Tags :

ionutc
SSL encription
How about if you want to enable SSL?
How can you do that in web.config?
Tags :

Page view tracker