Click to Rate and Give Feedback
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
<mailSettings> Element (Network Settings)

Configures mail sending options.

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

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.

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>
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Error in example code...      Andy Ballantine ... Thomas Lee   |   Edit   |  
This should be deliveryMethod="Network" (capitalisation on Network), raises a warning otherwise...

[tfl - 5 July 2008] - good catch, tagged as contentbug
Article could also have more information      Andy Ballantine   |   Edit   |  
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 What's this?: Add a tag
Flag as ContentBug
Poor example      theairdog   |   Edit   |  
And what if I don't want to use the default credentials?
Tags What's this?: Add a tag
Flag as ContentBug
Bypass Default Credentials Programmatically      Pakana   |   Edit   |  

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
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker