.NET System.Net.Mail.SmtpClient 类不会向 SMTP 事务发出 QUIT 命令
有人遇到过这个问题吗?如果是这样,你如何解决它?我们遇到了零星的超时问题,这受到了指责。
这里也报告了同样的问题:
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:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我不知道是否有更简单的方法来解决这个特定问题,但一个选择是下载 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.
您的应用程序是否在带有 IIS 的计算机上运行?如果是这样,您可以通过设置 SMTP 客户端的传送方法来利用内置 SMTP 服务,如下所示:
我在一些应用程序中使用它,它非常可靠。
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:
I am using this in a few applications, and it's very reliable.
这个问题在 .Net 4 中得到了解决。他们实现了 IDispose,这会发送 QUIT 命令并释放资源。
这是 MSDN 上相关文档的副本:
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:
看来我要找一个第三方产品来解决这个问题。单声道解决方案听起来很有趣,但我宁愿花几美元获得商业解决方案。
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.