System.Net.Mail.SmtpException: net_io_connectionclosed


  • I'm getting "System.IO.IOException: Unable to read data from the transport connection: net_io_connectionclosed." but only occasionally.  I'm confused because:

    1) The SMTP server is the local machine so why would the connection ever fail? and
    2) The error only happens sometimes

    There was a similar question posted here: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=418540&SiteID=1 but it seems they were having problems sending any mail to begin with.

    Here is the full stack trace:

    System.Net.Mail.SmtpException: Failure sending mail. ---> System.IO.IOException: Unable to read data from the transport connection: net_io_connectionclosed.
       at System.Net.Mail.SmtpReplyReaderFactory.ProcessRead(Byte[] buffer, Int32 offset, Int32 read, Boolean readLine)
       at System.Net.Mail.SmtpReplyReaderFactory.ReadLines(SmtpReplyReader caller, Boolean oneLine)
       at System.Net.Mail.SmtpReplyReaderFactory.ReadLine(SmtpReplyReader caller)
       at System.Net.Mail.SmtpReplyReader.ReadLine()
       at System.Net.Mail.CheckCommand.Send(SmtpConnection conn, String& response)
       at System.Net.Mail.DataStopCommand.Send(SmtpConnection conn)
       at System.Net.Mail.SmtpConnection.OnClose(Object sender, EventArgs args)
       at System.Net.ClosableStream.Close()
       at System.Net.Mail.MailWriter.Close()
       at System.Net.Mail.SmtpClient.Send(MailMessage message)

    I'm unable to recreate this error since it only happens every couple of days or even weeks.

    Has anyone had a similar error and been able to resolve it?

    Tuesday, September 11, 2007 9:29 PM

All replies

  • I am having the exact same problem. It is an intermittent issue.  I run the program without difficulties....next time it is run I get the failure message...I can leave it alone for an hour and run it again...sends fine.


    I have checked the SMTP settings numerous times.  There is no firewall issue.  I know the data is good for the .to and .from since that data worked before and always works on subsequent attempts...eventually.


    It almost seems to be a cache issue except I don't allow the page to be cached...but still after a period of time passes everything starts to work again without any changes.




    Wednesday, September 19, 2007 4:16 PM
  • WAFDOF95, did you ever find a solution for this problem?
    Wednesday, December 19, 2007 3:11 PM

    I'm having the same problem too.
    Friday, January 04, 2008 11:25 PM
  • Me too, just found that one, because in the meantime I've had no logging for that, but now we found out, that it's that error and if anyone has a clue about that - please tell it to us ;-) ...


    *Push that thread to the top* :-D

    Wednesday, January 16, 2008 1:00 PM
  • Still no luck?
    Wednesday, February 20, 2008 11:22 PM
  • Still no luck.  I have found a pattern though.  Seems that after 10 emails are sent...the next 10 fail...then 10 more will go before the next 10 fail.


    I set up a program that just sent emails and logged the results and that is when I discovered the pattern.



    Thursday, February 21, 2008 6:04 AM

    I ran into this today and the solution is tied somehow to the IP addresses you are using to secure the SMTP virtual server.  My server has multiple IP addresses bound to the same adapter and the VS was configured to use one of them.  However, I had all of the access restrictions to allow connections only from which is the source of the error (I believe.


    So, whatever the IP address your VS is listening on OR the IP your application is configured to use, configure the following areas:

    • Access/Connection control/Only the list below/[add your server ip]
    • Access/Relay restrictions/Only the list below/[add your server ip]
    • Configure your application to utilized the server ip, not localhost or
    • Proposed as answer by squebler Wednesday, May 12, 2010 4:15 AM
    Monday, February 25, 2008 7:15 PM
  • Thanks for the response Brad...had already tried those early on.  Our IT guys are baffled.  Our work around through the application is to catch the email transmission exception and write the data to a database.  A second program then retransmits the info from the data base until a successful send.....so strange that the pattern is 10 emails sent...10 fail...then back to 10 sent...




    Wednesday, February 27, 2008 5:17 AM
  • anybody found any solution. I am getting same error everytime.

    Friday, August 08, 2008 3:22 AM
  • Interesting thread with absolutely no one taking the proper approach to debugging it.

    Step 1) Download Wireshark
    Step 2) Start the trace and recreate the problem
    Step 3) Look for a FIN or RST for that conversation in the trace
    Step 4) Futher analysis can't continue until you determine what side is closing the conversation.

    If it's the client side then you approach the analysis by separating the layers.
    A) Is it a TCP/IP layer issue (socket timeout, badly formed packet, routing mistake, DNS failure etc.)
    B) Or is it an application layer issue?  (Perhaps the application issued the socket/stream close due to something it didn't like.

    If it's the server side
    A) Could it be too many requests at one time?
    B) A buffering issue, router issue on server side...
    C) The server application could have bugs...

    Too many times, especially with MS products for some reason there's too little proper debugging going on.  You just can't guess at this, it's way too complicated to do the "Seek and find" method of debugging.  Statements like "Did you try this" "Did you try that" are mostly really a statement of "I don't have a clue".
    • Edited by Mr. Javaman Friday, August 08, 2008 10:07 AM spelling
    Friday, August 08, 2008 10:06 AM
  • I'm getting the same problem when I set the defaultCredentials to true, but not when I'm using the pickup directory.

          <smtp deliveryMethod="Network">
            <network defaultCredentials="true" host="192.168.xxx.xxx" />
                    <specifiedPickupDirectory pickupDirectoryLocation="C:\inetpub\mailroot\Pickup" />

    (Numbers replace the xxx above)

    I have applied Wireshark to the problem and interestingly there is no trace info at all when I use the defaultCredentials, but there is when I use the pickup directory (ie the filter I used works) which may indicate that it's not getting to the SMTP server at all.

    Using the following settings in web.config:

          <source name="System.Net" switchValue="Verbose">
              <add name="System.Net" />
          <add name="System.Net" type="System.Diagnostics.TextWriterTraceListener" initializeData="Network.log" />
        <trace autoflush="true" indentsize="4" />

    I produced some logging information:

    System.Net Information: 0 : [2068] Associating MailMessage#61879347 with Message#3479815
    System.Net Verbose: 0 : [2068] SmtpClient::.ctor()
    System.Net Information: 0 : [2068] Associating SmtpClient#19886533 with SmtpTransport#27401293
    System.Net Verbose: 0 : [2068] Exiting SmtpClient::.ctor()  -> SmtpClient#19886533
    System.Net Verbose: 0 : [2068] SmtpClient#19886533::Send(MailMessage#61879347)
    System.Net Information: 0 : [2068] SmtpClient#19886533::Send(DeliveryMethod=Network)
    System.Net Information: 0 : [2068] Associating SmtpClient#19886533 with MailMessage#61879347
    System.Net Information: 0 : [2068] Associating SmtpTransport#27401293 with SmtpConnection#13943705
    System.Net Information: 0 : [2068] Associating SmtpConnection#13943705 with ServicePoint#13048313
    System.Net Information: 0 : [2068] Associating SmtpConnection#13943705 with SmtpPooledStream#57772374
    System.Net Error: 0 : [2068] Exception in the SmtpClient#19886533::Send - Unable to read data from the transport connection: net_io_connectionclosed.
    System.Net Error: 0 : [2068]    at System.Net.Mail.SmtpReplyReaderFactory.ProcessRead(Byte[] buffer, Int32 offset, Int32 read, Boolean readLine)
       at System.Net.Mail.SmtpReplyReaderFactory.ReadLines(SmtpReplyReader caller, Boolean oneLine)
       at System.Net.Mail.SmtpReplyReaderFactory.ReadLine(SmtpReplyReader caller)
       at System.Net.Mail.SmtpConnection.GetConnection(String host, Int32 port)
       at System.Net.Mail.SmtpTransport.GetConnection(String host, Int32 port)
       at System.Net.Mail.SmtpClient.GetConnection()
       at System.Net.Mail.SmtpClient.Send(MailMessage message)
    System.Net Verbose: 0 : [2068] Exiting SmtpClient#19886533::Send()

    I can't say I understand the above in any kind of detail.

    My set up is a Windows Server 2008 box on a domain with IIS and SMTP set up.  The fact that the pickup directory works implies that the basic functionality of the SMTP service is OK and it does route traffic.  Note that I had to allow NETWORK SERVICE permissions on the pickup directory to make that part work.

    Having Googled around the web, some people are recommending enabling relaying with the IP address or localhost (  Relaying is usually a very bad idea, so I don't really want to go down that route.  It seems to work with Windows Server 2003, but it's not working with Windows Server 2008.  I've also tried selecting All unassigned IP addresses as well as specific port IPs.  I can't see that this would make a lot of difference - I prefer to be specific.

    I suspect some kind of permissions issue, though I've tried all the different credentials methods (though specifying credentials and leaving them in plain text in the web.config file would be clearly unworkable in a production environment).



    Wednesday, September 24, 2008 9:23 PM
  • The problem is here System.Net Error: 0 : [2068] Exception in the SmtpClient#19886533::Send - Unable to read data from the transport connection: net_io_connectionclosed.

    Can you post the wireshark results when this happens?

    This is most likely a server side issue....but really SMTP isn't that difficult to understand, so if we can see the trace we can find out exactly what point in the session things are dying.

    Wednesday, September 24, 2008 10:50 PM
  • Hi Javaman

    The problem is that Wireshark is producing no capture data at all when using the network instead of the pickup directory.  The Wireshark filter I have in place is:

        (host and and port 25

    which I believe should give me something.  The former is the server address and the latter is the perimeter address.

    Thursday, September 25, 2008 9:51 AM
  • Wireshark produces no ouput...

    Interesting, I'm looking at the logging from above.  Let's take it one line at a time..
    The SMTPClient Ctor is called, executed and exited. (this looks ok)
    Then the SMTPClient.Send(Mailmessage) is called...
    I don't know your code or this logging format but let's try to dissect it.

    What does Associating xxxxx with yyyyyy mean?

    There appears to be three or four constucts of interest.
    1) Mailmessage
    2) SMTP Connection
    3) ServicePoint
    4) SMTPPooledStream

    Now proper debugging tells you to work from the problem backward.
    If we start from the System.NET.Error and go to one trace statement before that... we see that association of the connection with the SMTPPooledStream.  This most likely means that in your code somewhere around the SMTPPooledStream effort this is the root cause.

    Now, it could be that your code knows nothing about using SMTPPooledStreams.  If it does, then you're in luck because you can control it.  If it doesn't then there is something happening in the underlying support associated with (you guessed it) the next trace point up in the log which is a "ServicePoint"  Somewhere your code kicks off something whereby you "do" have control that needs to be investigated further..

    So if you take the list above and work backwards from items 4 to 1 until you can find in your code HOW you use those things, then you're on your way...

    Item 4) Google SMTPPooledStream Search
    Item 3) MSDN Service Point Class (This class sets TCP connection limits, it's a direct way to control TCP/IP packets.  Things such as maximum number of connections allowed., maximum idle time, etc.
    So because you say no packets make it to the network, it is safe to say that something is wrong with the way Items 4 and 3 are being used.  Can you shed any light on how you are using your POOLED Streams and the SERVICE Points?
    Thursday, September 25, 2008 12:14 PM
  • Javaman

    Thanks for your help so far.  Just to correct one thing: my Wireshark filter was:

        (host or and port 25

    I must have been half asleep copying it across to this post...

    Although I have working email arrangements with Windows 2000, because this didn't work, I used a Chris Pels VB example mildly refactored:

    Dim objMailMessage As MailMessage = New MailMessage()
    Dim objSmtpClient As SmtpClient = New SmtpClient()

    With objMailMessage
        .From =
    New MailAddress(System.Configuration.ConfigurationManager.AppSettings("fromEmailAddress"))
    New MailAddress(txtToAddress.Text.Trim()))
        .IsBodyHtml =
        .Subject = txtSubject.Text.Trim()
        .Body = txtBody.Text.Trim()
    End With



    Catch objSmtpException As SmtpException

    etc, etc, catching both SMTP and general exceptions, including inner exceptions.

    This code is very similar to many other examples out there.  As you can see I'm making so special provision for the SMTP configuration in the code and have kept the SMTP configuration in IIS 6.0 Manager with as few changes as possible (note: SMTP is configured using IIS6 tools on the IIS7-oriented Windows Server 2008).

    I'm now going to have a go at chasing down your references.


    Thursday, September 25, 2008 1:47 PM
  • The problem turned out to be a permissions issue.  I'm in the process of porting websites from a Windows 2000 box to a Windows 2008 platform and I missed a trick on the SMTP service config in Windows 2008

    Go to Internet Information Services (IIS) 6.0 Manager > SMTP Virtual Server > Right-click Properties > Access tab > Authentication button.

    By default in Windows 2000, all the boxes are ticked (checked), but in Windows 2003 and Windows 2008 only Anonymous access is ticked.  You have to select Integrated Windows Authentication to be able to send email over the network (ie not via the pickup directory nor exposing credentials in web.config).  I also chose to untick Anonymous access because it seemed like a security hole waiting to be exploited.

    You do not need to enable relaying for localhost or the IP address of this host computer.  Relaying is usually really bad news, so unless you have strong IT comms skills avoid it like the plague.

    This authentication configuration also works with a selected IP address or the All unassigned (see the General tab).

    If you are going down a pure programming route (ie less use of config files) then remember to add default credentials to the SMTP client object:

    Dim objSmtpClient As SmtpClient = New SmtpClient()
    objSmtpClient.defaultCredentials = True

    Hope this puts someone out of their misery.


    Tuesday, October 07, 2008 3:08 PM
  • Its an issue that has to do with ur spf record in dns that is preventing u from sending emails. Try contacting your host as it may take a few days for it to replicate.
    web developer
    Monday, March 22, 2010 1:22 AM
  • Thanks Brad.

    I did exactly that & it worked at first go.

    Thanks again.

    Thursday, May 20, 2010 12:35 PM
  • Ok so the transport issue was the client side complaining about not being able to get to the "transport" layer.  In other words, the send attempt was failing prior to any packet making it to the network.  The error message obviously is a tiny bit misleading, but accurate.  One small note on permissions, they purposely don't reflect much information as to root cause (why give hackers too much information).... Chalk this one up to being a "Error Siganture" of what a Permissions issue looks like.
    Monday, May 24, 2010 1:43 PM
  • Thank you
    Tuesday, May 25, 2010 8:30 PM
  • Bringing this thread back to life to hopefully get some input or advice for how to troubleshoot this problem when NOT using IIS SMTP Server.

    We are receiving the same error when our application tries to send messages, but we are using our app.config to point the SMTP Host to a dedicated SMTP Server.  This particular service is the only one in our environment throwing errors, all of the Web apps work fine.

    It appears it is failing before it ever attempts to hit the network layer, I search through the SMTP logs and I do not find any record of the message ever hitting the server.

    Any ideas for those of us not using Microsoft SMTP server?  Forgive the lack of detail, I'm in IT and have been given the investigation task by our Devs, I have a strong feeling this is application related though, but need some more information to bounce back to them.


    Saturday, June 26, 2010 3:23 AM
  • Step 1) Download Wireshark and run a trace during the recreation of the failure.

    Step 2) Read up on SMTP protocol so you can figure out the protocol.  In short there's a handshake of the TCP layer of Syn, SynAck, Ack followed by the SMTP layer which exchanges connection information and finally, the transaction. http://tools.ietf.org/html/rfc821#page-13 Will be the start of the SMTP protocol.  You should see something like Example 5 in the wireshark trace.  This will be followed by the SEND command http://tools.ietf.org/html/rfc821#page-11

    Post wireshark example here for analysis.


    Saturday, June 26, 2010 2:27 PM
  • I also was using a local SMTP and every nth email would fail and all my emails were exactly the same size.  This was occurring because I was hitting the SMTP session size limit.

    Friday, August 27, 2010 9:20 PM
  • Thanks Brad, Once I added the server ip to the list all my emails were sent ok.
    Tuesday, February 15, 2011 8:50 AM
  • Bingo- For Bard Turner. Thanks! This is the one that worked for me. Be careful when adding your that you aren't selecting the Deny everyone in this list option, but the allow everyone in this list. That was my problem. I had the IP's in the Access Control of IIS v6, I just had SMTP set to deny them, rather than allow.

    Thanks Brad!!!

    Tuesday, July 19, 2011 4:35 PM
  • On my system, the issue turned out to be that I had bound the SMTP service to one IP address, and evidently the application was trying to bind to either localhost or to the other NIC on the machine.  Changing the IP address to (All Unassigned) worked for me.
    Tuesday, November 08, 2011 4:08 PM