简体   繁体   English

smtpClient不读取Web.config

[英]smtpClient doesn't read the Web.config

In my MVC4 application, I'm trying to get mail sent using Web.config for configuration settings. 在我的MVC4应用程序中,我正在尝试使用Web.config发送邮件以进行配置设置。 I have papercut running as a mock SMTP server. 我有剪纸作为模拟SMTP服务器运行。 When I try to use smtpClient and set host="localhost" in my code (that is, not through Web.config) everything works just fine. 当我尝试使用smtpClient并在我的代码中设置host =“localhost”时(也就是说,不是通过Web.config),一切正常。

My Web.config 我的Web.config

  <system.net>
    <mailSettings>
      <smtp deliveryMethod="Network" from="someone@somewhere.net">
        <network
           host="localhost"
           userName=""
           password=""
           defaultCredentials="true" />
      </smtp>
    </mailSettings>
  </system.net>

My code 我的代码

SmtpClient client = new SmtpClient();
client.Send(myEmailObject);

The error 错误

The SMTP host was not specified 未指定SMTP主机

There are multiple web.config's in a ASP.NET MVC application. ASP.NET MVC应用程序中有多个web.config。 In order for most of the system related settings to take effect, they have to be placed inside the application's root web.config. 为了使大多数系统相关设置生效,必须将它们放在应用程序的根web.config中。 That means the one that the server sees as "~/web.config" and that is in the root folder of the Visual Studio solution. 这意味着服务器将其视为“〜/ web.config”并且位于Visual Studio解决方案的根文件夹中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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