简体   繁体   中英

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="whatever@whatever.com.br" 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!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM