Is system.net.mail.smptclient disconnected from the server?

We have several pages on our web systems that use the .net system.net.mail control to send emails. The fact is that it works fine, except that now it starts to look like the smptclient class cannot actually disconnect from the server, so the SMTP server leaves this connection, and we have finished the maximum number of connections that we are allowed to open at the same time on the SMTP server, although it sends only one email at a time.

(For the record, this is an .net 2.0 asp.net application written in VB, and we are pretty sure that this is not some kind of security / virus / spam situation.)

Google and MSDN did not find anything convincing, but enough heresy in the blogs to confirm that we can not hallucinate.

Does anyone else have such a problem? (And managed to fix it?)

Of course, if it works fine, and we hallucinate, it would be nice to find out.;)

+1
source share
5 answers

The problem with e-mail that is not sent immediately using SmtpClient is that under certain conditions it does not send the β€œQUIT” SMTP command when it should (that is, it does not shut down properly). I used the following code to successfully disconnect communications in the past:

var smtp = new SmtpClient(); smtp.ServicePoint.MaxIdleTime = 1; smtp.ServicePoint.ConnectionLimit = 1; smtp.Send(message); 

This makes the smtpclient object disconnect as early as possible. Also, make sure that your smtpclient instance falls out of scope pretty quickly (i.e., don't store a static link in it).

+3
source share

Are you deleting your MailMessage correctly after sending it? I have never seen any sign that SmtpClient was not closing it, although

+1
source share

Have you checked the StmpDeliveryMthod property of the StmpClient class?

+1
source share

A handy tool for this type of question I’ve connected is : TcpView (\\ live.sysinternals.com \ Tools \ Tcpview.exe) from SysInternals (now Microsoft)

+1
source share

Make sure that they are installed on the mail server (provided that the windows) -

[HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Services \ Tcpip \ Parameters] "TcpTimedWaitDelay" = DWORD: 0000001e "MaxFreeTcbs" = DWORD: 000007d0 "MaxUserPort" = DWORD: 0000fffe

+1
source share

All Articles