搜索 StackOverflow,我发现了这个关于如何从 Web.Config 检索 SMTP 设置的问题,但没有关于如何将 SMTP 更新回 web.config 文件的详细信息。
我从以下代码开始:
Configuration webConfig = WebConfigurationManager.OpenWebConfiguration("~");
MailSettingsSectionGroup settings =
(MailSettingsSectionGroup)webConfig.GetSectionGroup("system.net/mailSettings");
SmtpSection smtp = settings.Smtp;
SmtpNetworkElement net = smtp.Network;
但很快被 Intellisense 发现,它SmptSection.Network
是一个 Get(又名“只读”)访问器。
那么我应该如何以编程方式将我的 SMTP 数据写回 web.config 呢?