SmtpClient 类未从 Web.Config 文件中获取默认参数

发布于 2024-07-09 17:57:10 字数 651 浏览 5 评论 0原文

配置文件:

<system.net>
<mailSettings>
<smtp from="[email protected]">
<network
host="mail.xxxxxx.com"
port="25"
password="password"
userName="[email protected]"
defaultCredentials="false"
/>
</smtp>
</mailSettings>
</system.net>

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

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

如何解决这个问题?

config file :

<system.net>
<mailSettings>
<smtp from="[email protected]">
<network
host="mail.xxxxxx.com"
port="25"
password="password"
userName="[email protected]"
defaultCredentials="false"
/>
</smtp>
</mailSettings>
</system.net>

I've already tried defaultCredentials="true" but i recieved following message:

System.FormatException: Smtp server returned an invalid response.

how to fix the problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

忆悲凉 2024-07-16 17:57:11

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

Set the deliveryMethod property on the smtp element to 'network'.

末が日狂欢 2024-07-16 17:57:11

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

现在工作正常:))

sorry, had the web.config from the Views folder in ASP.NET MVC open, not the one in the application root - DOH!!!!!

Working fine now :))

把梦留给海 2024-07-16 17:57:11

您将这些元素放置在 web.config 中的什么位置? 它们应该看起来像这样:

<configuration>
  <system.net>
    <mailSettings>
      <smtp from="[email protected]">
        <network host="mail.xxxxxx.com" port="25" password="password" userName="[email protected]" defaultCredentials="false"/>
      </smtp>
    </mailSettings>
  </system.net>
<configuration>

但根据您收到的异常,听起来配置正在工作,但您的消息格式不正确。 您的邮件消息是什么样的? 您传递的发件人、电子邮件、主题和正文是什么?

Where have you placed these elements inside your web.config? They should look like this:

<configuration>
  <system.net>
    <mailSettings>
      <smtp from="[email protected]">
        <network host="mail.xxxxxx.com" port="25" password="password" userName="[email protected]" defaultCredentials="false"/>
      </smtp>
    </mailSettings>
  </system.net>
<configuration>

But based on the exception you're getting it sounds like the config is working but your message is improperly formatted. What does your MailMessage look like? What are you passing as your From, Email, Subject and Body?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文