views:

893

answers:

2

For some time now I've been storing my connection and app settings in an external file and just referencing that file via my web.config. This works really well because it allows me to keep separate connection strings and app settings. This is really handy since I find during development I will often make many changes to the webconfig and I hate having to manage the environment specific values every time I need to update my web.config.

Is there anyway I can achieve this with he SMTP configuration sections in the web.config.

A: 

My software stores it in the registry, even in production.

Joshua
Wow.... wish SO allowed assigning medals..... ;-)
Doug
+5  A: 

Sure, you can use the configSource attribute.

Example:

<system.net>
  <mailSettings>
   <smtp configSource="MailSettings.config"/>
  </mailSettings>
</system.net>

Then put your mailSettings configuration data in MailSettings.config

So then your MailSettings.config file would have something like:

    <network 
    host="relayServerHostname" 
    port="portNumber"
    userName="username"
    password="password" />

Update: looks like it may need to actually go in the smtp node to work properly, so I've updated the above code to indicate that - same idea, only this one should work. :)

Carson McComas
Cool! I didn't know you could do that!
Christian Payne
This is one of those ASP.NET features I wish I knew earlier!
Cloud
Ahhh I was trying this previously I was just forgeting to put it inside the system.net node... whooops.. Thanks for the heads up.