.NET System.Net.Mail.SmtpClient 类不会向 SMTP 事务发出 QUIT 命令

发布于 2024-08-05 11:48:45 字数 248 浏览 5 评论 0原文

有人遇到过这个问题吗?如果是这样,你如何解决它?我们遇到了零星的超时问题,这受到了指责。

这里也报告了同样的问题:

http://www.vbforums.com/showthread.php?p=3609268

Has anybody had issues with this? If so, how do you get around it? We are getting sporadic timeout issues and this is getting blamed.

The same issue is reported here as well:

http://www.vbforums.com/showthread.php?p=3609268

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

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

发布评论

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

评论(4

酷到爆炸 2024-08-12 11:48:45

我不知道是否有更简单的方法来解决这个特定问题,但一个选择是下载 Mono 的 SmtpClient 的源代码并使用它(如有必要进行修改)。他们的版本肯定会发送退出命令。

我从事的一个项目要求我们发送大量电子邮件。 .NET 的实现效率太低,没有提供任何在同一个 SMTP 会话中发送多封不同电子邮件的方法。我们转而使用 Mono 的实现并对其进行修改,以允许我们手动控制何时发送 QUIT 命令和关闭连接。为此,我们必须将总共 25 个相关的 Mono 类合并到我们的项目中(主要是复制+粘贴和编辑命名空间)。

这似乎有点极端,但如果没有办法解决这个问题,它可能是您最好的第 3 方替代方案:它是免费的,不需要大量工作,而且它的 API 几乎相同到本机 SmtpClient 的。

I don't know if there's an easier way to work around this specific problem, but one option would be to download the source for Mono's SmtpClient and use that (modifying if necessary). Their version definitely does send a QUIT command.

One project that I work on required us to send large numbers of emails. .NET's implementation was too inefficient, not providing any way to send multiple distinct emails in the same SMTP session. We fell back on using Mono's implementation and modifying it to allow us to manually control when the QUIT command was sent and the connection closed. There were a total of 25 relevant Mono classes that we had to merge into our project for this (mostly copy+paste and edit namespace).

It seems a little extreme, but if there's no way to work around the issue, it may be your best 3rd-party alternative: it's free, it's not a great deal of work and its API is almost identical to the native SmtpClient's.

走过海棠暮 2024-08-12 11:48:45

您的应用程序是否在带有 IIS 的计算机上运行?如果是这样,您可以通过设置 SMTP 客户端的传送方法来利用内置 SMTP 服务,如下所示:

var client = new SmtpClient 
{ 
    DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis 
};

我在一些应用程序中使用它,它非常可靠。

Is your application running on a machine with an IIS? If so, you could take advantage of the built-in SMTP Service by setting the delivery method of your SMTP client like this:

var client = new SmtpClient 
{ 
    DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis 
};

I am using this in a few applications, and it's very reliable.

梨涡少年 2024-08-12 11:48:45

这个问题在 .Net 4 中得到了解决。他们实现了 IDispose,这会发送 QUIT 命令并释放资源。

这是 MSDN 上相关文档的副本:

SmtpClient类没有Finalize
方法,因此应用程序必须调用
处置以显式释放
资源。处置方法
迭代所有已建立的
与 SMTP 服务器的连接
在 Host 属性中指定并且
发送 QUIT 消息,然后
优雅地结束 TCP 连接。
Dispose 方法还释放
Socket 使用的非托管资源
并可选择处置托管的
资源。

完成后调用 Dispose
使用 SmtpClient。处置
方法将 SmtpClient 留在
无法使用的状态。调用 Dispose 后,
您必须释放所有对
SmtpClient等垃圾收集器
可以收回记忆
SmtpClient 正在占用。

It is solved in .Net 4. They implemented IDispose and this sends the QUIT command and frees resources.

This is a copy of the relevant documentation on MSDN:

The SmtpClient class has no Finalize
method, so an application must call
Dispose to explicitly free up
resources. The Dispose method
iterates through all established
connections to the SMTP server
specified in the Host property and
sends a QUIT message followed by
gracefully ending the TCP connection.
The Dispose method also releases the
unmanaged resources used by the Socket
and optionally disposes of the managed
resources.

Call Dispose when you are finished
using the SmtpClient. The Dispose
method leaves the SmtpClient in an
unusable state. After calling Dispose,
you must release all references to the
SmtpClient so the garbage collector
can reclaim the memory that the
SmtpClient was occupying.

じее 2024-08-12 11:48:45

看来我要找一个第三方产品来解决这个问题。单声道解决方案听起来很有趣,但我宁愿花几美元获得商业解决方案。

Looks like I'm going to find a 3rd party product to fix the problem. The mono solution sounds interesting, but I'd rather spend a few bucks and get a commercial solution.

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