本文介绍了.NET最佳方法来发送电子邮件(System.Net.Mail有问题)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这似乎是pretty的直线前进。我需要从某些ASP.NET应用程序发送电子邮件。我需要做到这一点始终没有奇怪的错误,没有CPU利用率经历的屋顶。我说的不是群发邮件,只是偶尔的电子邮件。

This seems to be pretty straight forward. I need to send email from some ASP.NET applications. I need to do this consistently without strange errors and without CPU utilization going through the roof. I'm not talking about mass emailing, just occasional emails.

System.Net.Mail的出现的是可怕的破碎。该SmtpClient不会发出退出命令(也可能是因为微软(R)不感兴趣下面的规范),因此连接被打开。因此,如果有人试图就此前,以电子邮件的最后关闭,您可以了解太多的连接,从SMTP服务器错误打开。这是一个错误,微软(R)是固定完全不感兴趣。在这里看到:

System.Net.Mail appears to be horribly broken. The SmtpClient does not issue the Quit command (it may be because Microsoft(R) is not interested in following specifications), therefore a connection is left open. Therefore, if someone tries to email before that connection finally closes, you can get errors from the SMTP Server about too many connections open. This is a bug that Microsoft(R) is completely uninterested in fixing. See here:

<一个href="http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=146711">http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=146711

另外,如果你看看周围的一些建议使用此code来解决这个问题:

Also, if you look around some suggest to use this code to solve this problem:

smtpClient.ServicePoint.MaxIdleTime = 1;
smtpClient.ServicePoint.ConnectionLimit = 1;

好了,是的,它解决连接的问题被悬空。然而,这种持续,尝试在服务器上,如果你喜欢,使在该进程(在本例中的w3wp.exe)正在运行来跳,保持在100%,直到您的应用程序池被回收的CPU。无论出于何种原因,运行的Mscorwks.dll线程!CreateApplicationContext是罪魁祸首。

Ok, yes that does "solve" the problem of connections being left open. However, this consistently, try it on a server if you like, causes the CPU on which the process (in this case w3wp.exe) is running to jump and remain at 100% until your application pool is recycled. For whatever reason, the thread that runs mscorwks.dll!CreateApplicationContext is the culprit.

这有非常好的副作用,如果你是不赞成持续100%的CPU使用率一个虚拟主机上运行,​​你会得到你的应用程序池禁用。因此,这不是简单,例如一些建议。

This has the very nice side effect that if you are running on a web host that frowns on sustained 100% CPU usage, you will get your application pool disabled. So this is not as trivial as some suggest.

所以我的问题是怎样做的?我需要做的就是这么简单;然而,让那些太多的连接打开的错误是不能接受的,也不是100%的CPU使用率。我不想购买第三方组件,不是因为我便宜,但我买够组件和MSDN订阅,它似乎疯了,不得不掏出$ 100-简单的SMTP功能300 $。

So my question is what to do? What I need to do is so simple; however getting those "too many connections open" errors is not acceptable and nor is the 100% CPU usage. I don't want to purchase a third party component, not because I'm cheap, but I buy enough components and MSDN subscription that it seems crazy to have to shell out $100-$300 for simple SMTP functionality.

我读到设置MaxIdleTime高可以帮助,但我很怀疑这一点。我不想冒险我的应用程序池被禁用,只是因为微软不想遵循SMTP规范。

I read that setting the MaxIdleTime higher can help but I'm skeptical of that. I don't want to risk my app pool being disabled just because Microsoft doesn't want to follow the SMTP specification.

编辑:我看着quiksoft.com组件,但它不支持SMTP认证,它的成本$ 500。我们有了可以解决这个问题。

I looked at quiksoft.com components, however it does not support SMTP authentication and it costs $500. There's got to be a solution to this problem.

推荐答案

我面临着同样的CPU利用率的问题,介绍的设置。最后我开罚单与微软以确定问题的原因。 CPU使用率问题出在的ServicePoint类。内部中的ServicePoint类,有运行每隔(MaxIdleTime / 2)毫秒的计时器。看到这个问题?通过改变MaxIdleTime值为2时,CPU利用率将下降到正常水平。

I faced the same CPU utilization problem with the settings described. I ended up opening a ticket with Microsoft to determine the cause of the problem. The CPU utilization problem lies in the ServicePoint class. Internally in the ServicePoint class, there is a timer that runs every (MaxIdleTime/2) milliseconds. See the problem? By changing the MaxIdleTime value to 2, the CPU utilization will drop down to normal levels.

这篇关于.NET最佳方法来发送电子邮件(System.Net.Mail有问题)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 18:03