2

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

网页配置

<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>
4

0 回答 0