来自Web.config的外部smtp.config不起作用

时间:2013-08-15 17:25:24

标签: asp.net-mvc web-config

我从Web.config中将<smtp />设置提取到外部smtp.config。现在,当我运行应用程序时,我收到错误The SMTP host was not specified.

的Web.config

<configuration>
    <system.net>
       <mailSettings>
          <smtp configSource="smtp.config" />
       </mailSettings>
    </system.net>
</configuration>

smtp.config

<?xml version="1.0" encoding="utf-8" ?>
<smtp from="name@email.com">
  <specifiedPickupDirectory pickupDirectoryLocation="C:\Users\user\Documents\Projects\_TempEmail"/>
</smtp>

感谢。

修改

更完整版的Web.config。

<configuration>
      <configSections>
        <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
        <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
      </configSections>
      <system.net>
        <mailSettings>
          <smtp configSource="smtp.config" />
        </mailSettings>
      </system.net>
      <connectionStrings>
        <!-- connection strings here -->
      </connectionStrings>
      <appSettings>
        <!-- app settings here -->
      </appSettings>
      <system.web>
      <!-- more settings here -->
      </system.web>
      <system.webServer>
      <!-- more settings here-->
      </system.webServer>
      <runtime>
      <!-- more settings here -->
      </runtime>
      <entityFramework>
      <!-- more settings here -->
      </entityFramework>
  </configuration>

编辑2:

正确的smtp.config工作如下。

我失踪了deliveryMethod="SpecifiedPickupDirectory"

<?xml version="1.0" encoding="utf-8" ?>
<smtp from="name@email.com" deliveryMethod="SpecifiedPickupDirectory">
  <specifiedPickupDirectory pickupDirectoryLocation="C:\Users\user\Documents\Projects\_TempEmail"/>
</smtp>

0 个答案:

没有答案