加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net – 如何以编程方式将SMTP服务器详细信息存储(保存)回web

发布时间:2020-12-16 09:59:04 所属栏目:asp.Net 来源:网络整理
导读:搜索StackOverflow,我找到了 this question on how to Retrieve SMTP settings from Web.Config,但没有关于如何将SMTP更新回web.config文件的详细信息. 我从以下代码开始: Configuration webConfig = WebConfigurationManager.OpenWebConfiguration("~");Ma
搜索StackOverflow,我找到了 this question on how to Retrieve SMTP settings from Web.Config,但没有关于如何将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呢?

解决方法

你应该可以做这样的事情,这有用吗?:

Configuration webConfig = WebConfigurationManager.OpenWebConfiguration("~");
MailSettingsSectionGroup settings =
    (MailSettingsSectionGroup)webConfig.GetSectionGroup("system.net/mailSettings");
SmtpSection smtp = settings.Smtp;
SmtpNetworkElement net = smtp.Network;
net.Port = 25;
net.Host = "localhost";
webConfig.Save();

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读