怎么我的ASP.NET应用程序会自动从web.config中获取SMTP设置? [英] How does my ASP.NET app get the SMTP settings automatically from web.config?

查看:87
本文介绍了怎么我的ASP.NET应用程序会自动从web.config中获取SMTP设置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到,我们永远只是像:

I noticed that we always just are like:

SmtpClient mSmtpClient = new SmtpClient();
// Send the mail message
mSmtpClient.Send(mMailMessage);

和凭据设置的唯一的地方是在web.config中:

And the only place the credentials are set are in web.config:

  <system.net>
    <mailSettings>
      <smtp>
        <network host="xxx.xx.xxx.229" userName="xxxxxxxx" password="xxxxxxxx"/>
      </smtp>
    </mailSettings>
  </system.net>

所以我的问题是,它如何自动的把他们救出来?

So my question is, how does it automagically get them out?

推荐答案

指出SmtpClient的参数的构造函数从应用程序或计算机配置文件读取配置的文件。对于Web应用程序,该应用程序配置文件是web.config中。这也意味着,如果mailSettings元素没有在Web.config中设置,它会寻找在machine.config中的设置,才放弃:

The documentation states that the parameterless constructor of SmtpClient reads its configuration from the application or machine configuration file. For a Web application, the application configuration file is web.config. This also means that if the mailSettings element is not set in Web.config, it will look for settings in machine.config, before giving up:

这构造函数初始化主机,
  凭据和端口属性
  新SmtpClient通过使用
  在应用程序或设备设置
  配置文件。

"This constructor initializes the Host, Credentials, and Port properties for the new SmtpClient by using the settings in the application or machine configuration files."

这篇关于怎么我的ASP.NET应用程序会自动从web.config中获取SMTP设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆