views:

50

answers:

4

hi,

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\XXX.com\httpdocs\web.config line 64) THIS IS MY WEB CONFIG CODE ......

<system.net>
<mailSettings>
  <smtp>
    <network host="webmail.XXXX.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>

A: 

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

this. __curious_geek
A: 

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.

Johann Strydom
+1  A: 

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.

Nikos Steiakakis
A: 

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

Peter Forss