SmtpClient in .net 2.0 does not close connection to mail server

SMTPClient class provided in the .net framework 2.0 is buggy and NEVER sends a QUIT command to the SMTP Server. As per the SMTP protocol once the communication is done by the client( web, windows application or any other client app) with email server, it has to send QUIT command in the end to close the connection with Mail Server. This issue has been reported to Microsoft Connect.

SmtpClient in .net 2.0 doesn’t have dispose method which can release connection with Mail server and free up any resources used. That means if your application is sending too many emails using smtpclient.send function, it oftens reach to maximum number of allowed connections with mail server and results in one of the following exceptions:

"Service not available, closing transmission channel. The server response was: #4.x.2 Too many messages for this session"
"System.Net.WebException: Unable to connect to the remote server"
"System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond"

Its fixed in .Net Framework 4.0

Good news is that, the .Net 4.0 now supports dispose method in SmtpClient class. according to MSDN: It sends a QUIT command to the SMTP server, and gracefully ends the TCP connection to releases all resources used by the current instance of the SmtpClient class.

Comments (2) -

  • outsourcing consultants

    outsourcing consultants

    6/4/2012 3:41:17 AM | Reply

    If you are  a beginner in IT outsourcing then this list is for you.

  • Steve Johnson

    Steve Johnson

    8/16/2016 1:48:17 PM | Reply

    This is useful information.
    Dispose method has been added in .Net 4.0 which sends QUIT command to Mail server

Pingbacks and trackbacks (2)+