views:

53

answers:

1

I'd like to know if there is an automated method to add e-mail settings to web.config.

There is already an e-mail set, and it's currently like this:

<system.net>
    <mailSettings>
        <smtp deliveryMethod="Network">
            <network host="0.0.0.0" port="25" userName="[email protected]" password="stackoverflow" />
        </smtp>
    </mailSettings>
</system.net>

So what I want is:

1 - How do I add a new e-mail in there set by textboxes in the webform ?
2 - How do I differentiate which one I want to gather at the time ? could you give me a simple C# example on how to get the configs in one of the two ?

Thanks in advance!

+2  A: 

This seems like a requirement better suited to a database than the web configuration. There are ways to add/update items in the web configuration if you feel like you must. Look at the WebConfigurationManager class and it's associated methods. Note that the id running the AppPool will need write access to the web.config file in order for this to work. That in itself is a risk.

tvanfosson
There is write access, and I do want to set it on the web.config for some reason, in fact, it's already set at the database, and I'm migrating this particular one to web.config. Thank you!
MarceloRamires
@MarceloRamires: don't forget that modifying the web.config will cause the application to restart, which may have repercussions for any other users on the website - I agree with tvanfosson here - if you're going to be chaning this on a frequent, ad-hoc basis, you're better off putting it in a database or similar.
Zhaph - Ben Duguid
@Zhaph - Ben Duguid Since it's just e-mail setup, it's goingn to be a first run thing. Then there's no issue..
MarceloRamires