代码之家  ›  专栏  ›  技术社区  ›  Old Geezer

我可以在Azure门户中设置SMTP设置吗?

  •  1
  • Old Geezer  · 技术社区  · 7 年前

    <mailsettings> 下元素 <system.net> 在web.config中。

    是否有办法在Azure门户的应用程序设置或其他地方配置这些内容,或者我必须通过编辑web.config来管理这些内容?

    我的意思不是从书上读 appSetting 键,然后将它们填充到 System.Net.Mail <mailSettings> 元素)何时 SmtpClient 是实例化的。

    1 回复  |  直到 7 年前
        1
  •  1
  •   rickvdbosch    7 年前

    我的意思不是从书上读 appSetting 键,然后将它们填充到 System.Net.Mail 物体。我希望参数(例如主机、端口、凭据、发送方等)在运行时自动从配置文件中填充 SmtpClient 是实例化的。

    不,你不能。

    Application Settings . (里面有什么设置 覆盖

    因为您使用的是 mailSettings SmpClient .

    您可以创建一个自定义

    var smtpServerHost = CloudConfigurationManager.GetSetting("SmtpServerHost");
    var smtpServerPort = int.Parse(CloudConfigurationManager.GetSetting("SmtpServerPort"));
    var smtpServerUserName = CloudConfigurationManager.GetSetting("SmtpServerUserName");
    var smtpServerPassword = CloudConfigurationManager.GetSetting("SmtpServerPassword");
    
    var client = new SmtpClient(smtpServerHost, smtpServerPort);
    client.Credentials = new NetworkCredential(smtpServerUserName, smtpServerPassword);
    

    (受此帖子启发: How to set mailSettings from Azure App Service - Application settings )

    推荐文章