Surya sasidhar
Surya sasidhar

Reputation: 30313

Web.config in asp.net?

I have a doubt in my web application can i place two nework tags in smtp mailSetting tag. I PLACED in SMTP two network tags , BUT WHEN I AM SENDING MAIL I AM GETTING THIS ERROR. The element may only appear once in this section. (C:\Inetpub\vhosts\example.com\httpdocs\web.config line 64) THIS IS MY WEB CONFIG CODE ......

<system.net>
<mailSettings>
  <smtp>
    <network host="webmail.example.com" port="25" userName="[email protected]"  Password="asdf"  defaultCredentials="false"/>
    <network host="webmail.yyy.com" port="25" userName="[email protected]"  Password="asdf254"  defaultCredentials="false"/>
  </smtp>
</mailSettings>

Upvotes: 0

Views: 679

Answers (4)

Peter &#214;rneholm
Peter &#214;rneholm

Reputation: 2858

If you want different settings for different deployment configurations I would use Web.config Transformation. It was introduced in ASP.NET 4.0.

You can have one default setting for when you build the project on your localhost and when you publish it to the server, another one will be used.

Reference: http://msdn.microsoft.com/en-us/library/dd465326(VS.100).aspx

Upvotes: 0

Nikos Steiakakis
Nikos Steiakakis

Reputation: 5745

You can use the AppSettings section and add as many configuration values as you like. You can use for example:

<appSettings>
   <add key="SMTP1" value="smtpserver1"/>
   <add key="SMTP2" value="smtpserver2"/>
   <add key="SMTP3" value="smtpserver3"/>
   <add key="SMTP4" value="smtpserver4"/>
</appSettings>

and then in your code decide which server to use.

Upvotes: 1

Johann Strydom
Johann Strydom

Reputation: 1492

The SMTP details section is used to specify default values. To have more than one you need to write some code to read your own custom values from appsessings or even implement your own config section.

Upvotes: 0

this. __curious_geek
this. __curious_geek

Reputation: 43217

Nope you cannot. Though you can carry as many details in AppSettings section.

Upvotes: 0

Related Questions