Marcelo
Marcelo

Reputation: 3391

Adding different e-mail's in ASP.NET's web.config at run-time

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!

Upvotes: 0

Views: 468

Answers (1)

tvanfosson
tvanfosson

Reputation: 532595

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.

Upvotes: 2

Related Questions