【问题标题】:SmtpClient class not picking up default parameters from Web.Config fileSmtpClient 类未从 Web.Config 文件中获取默认参数
【发布时间】:2008-11-30 21:37:53
【问题描述】:

配置文件:

<system.net>
<mailSettings>
<smtp from="YYYYY@xxxxxx.com">
<network
host="mail.xxxxxx.com"
port="25"
password="password"
userName="user@xxxxxx.com"
defaultCredentials="false"
/>
</smtp>
</mailSettings>
</system.net>

我已经尝试过 defaultCredentials="true" 但收到以下消息:

System.FormatException:Smtp 服务器返回无效响应。

如何解决问题?

【问题讨论】:

    标签: c# .net asp.net-mvc smtpclient


    【解决方案1】:

    将 smtp 元素的 deliveryMethod 属性设置为“network”。

    【讨论】:

      【解决方案2】:

      抱歉,打开了 ASP.NET MVC 中 Views 文件夹中的 web.config,而不是应用程序根目录中的那个 - DOH!!!!!!

      现在工作正常 :))

      【讨论】:

      • 我也这样做了...花了我几个小时的挠头。
      【解决方案3】:

      您将这些元素放在 web.config 中的什么位置?它们应该如下所示:

      <configuration>
        <system.net>
          <mailSettings>
            <smtp from="YYYYY@xxxxxx.com">
              <network host="mail.xxxxxx.com" port="25" password="password" userName="user@xxxxxx.com" defaultCredentials="false"/>
            </smtp>
          </mailSettings>
        </system.net>
      <configuration>
      

      但是根据您收到的异常,听起来配置正在运行,但您的消息格式不正确。您的 MailMessage 是什么样的?您传递的 From、Email、Subject 和 Body 是什么?

      【讨论】:

        猜你喜欢
        • 2013-01-29
        • 2013-03-02
        • 1970-01-01
        • 1970-01-01
        • 2010-10-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多