"Unable to read data from the transport connection: net_io_connectionclosed." - Windows Vista Business and SMTP

90,491

Solution 1

There are several things that can cause this problem, and here are some of the things that I've found. Questions: You mention "Exchange" -- Is this an exchange server? Does the host require authentication (maybe you need to add authentication to the client)? What I would try doing first is assigning the host to the static IP address instead of the host name to see if that works first. If it does then it's most likely a problem with the DNS mapping.

If you are running your exchange server with Virtualization, you need to configure the SmtpClient to the host IP of the Virtual Server, not the physical hosting server name or IP. Right click on Default SMTP virtual server, select Properties, then go to Access tab, click Relay then add the IP address of the computer that send SMTP request to the SMTP server. (ASP.net site)

If this doesn't work, it's because the server is blocking you from sending SMTP packets. You need to make sure to add the box you are sending the SMTP messages from to the SMTP server. This is done through IIS's authentication tab.

I would also like to point out that you should dispose the mail client, or use the client in a "using" statement. This will make sure that the "QUIT" is sent to the server and gracefully close the connection.

using(SmtpClient smtp = new SmtpClient())
{
    smtp.Host = "emailservername";
    smtp.Port = 25;
    smtp.UseDefaultCredentials = true;
    smtp.Send(mail)
}

Solution 2

Restart IIS. I know this sounds silly, to do a restart for everything. (and sorry to bump up an old thread). But sometimes restarting IIS works magic. I faced the exact same issue and restarting solved it.

Might have happened cause temporarily the name 'localhost' couldn't be resolved. I;m just posting here so that someone who faces it now will probably try this quick fix before attempting to investigate further. Hope it helps

Solution 3

If you are using localhost (Use Localhost) in IIS 7, then change it to IP address of the machine instead of localhost or 127.0.0.1

Also follow below link to update your mail server relay accordingly:

Mailbox unavailable. The server response was: 5.7.1 Unable to relay for [email protected]

Solution 4

If you've specified an IP address in the SMTP Service settings then make sure you're specifying that IP address of the machine within IIS7 and not putting localhost.

IIS7 makes it easy to select 'localhost' but that will lead to this error if the IP for instance is 10.0.0.1

Solution 5

Vista and Windows 7 does not have any SMTP server, this facility has been removed since Windows XP, so you need to setup your SMTP server explicitly, several tools are available in market for that, you can check that out. Also once you configure the SMTP, remember to check the server name which you would be using to send the e-mail.

Share:
90,491
john.da.costa
Author by

john.da.costa

Driving Business Results through Data - Working with The Cloud Data Platform. Currently Working at Snowflake - The Data Cloud.

Updated on February 19, 2022

Comments

  • john.da.costa
    john.da.costa about 2 years

    Unable to test sending email from .NET code in Windows Vista Business.

    I am writing code which I will migrate to an SSIS Package once it its proven. The code is to send an error message via email to a list of recipients.

    The code is below, however I am getting an exception when I execute the code.

    I created a simple class to do the mailing... the design could be better, I am testing functionality before implementing more robust functionality, methods, etc.

    namespace LabDemos
    {
        class Program
        {
            static void Main(string[] args)
            {
                Mailer m = new Mailer();
                m.test();    
            }
        }
    }
    
    namespace LabDemos
    {
        class MyMailer
        {    
            List<string> _to = new List<string>();
            List<string> _cc = new List<string>();
            List<string> _bcc = new List<string>();
            String _msgFrom = "";
            String _msgSubject = "";
            String _msgBody = "";            
    
            public void test(){
            //create the mail message
            MailMessage mail = new MailMessage();
    
            //set the addresses
            mail.From = new MailAddress("[email protected]");            
    
            //set the content
            mail.Subject = "This is an email";
            mail.Body = "this is a sample body";
            mail.IsBodyHtml = false;    
    
            //send the message
            SmtpClient smtp = new SmtpClient();
            smtp.Host = "emailservername";
            smtp.Port = 25;
            smtp.UseDefaultCredentials = true;
            smtp.Send(mail);            
        }
    }
    

    Exception Message

    Inner Exception
    {"Unable to read data from the transport connection: net_io_connectionclosed."}
    
    Stack Trace
    "   at System.Net.Mail.SmtpReplyReaderFactory.ProcessRead(Byte[] buffer, Int32 offset, Int32 read, Boolean readLine)\r\n   at System.Net.Mail.SmtpReplyReaderFactory.ReadLines(SmtpReplyReader caller, Boolean oneLine)\r\n   at System.Net.Mail.SmtpReplyReaderFactory.ReadLine(SmtpReplyReader caller)\r\n   at System.Net.Mail.SmtpConnection.GetConnection(String host, Int32 port)\r\n   at System.Net.Mail.SmtpTransport.GetConnection(String host, Int32 port)\r\n   at System.Net.Mail.SmtpClient.GetConnection()\r\n   at System.Net.Mail.SmtpClient.Send(MailMessage message)"
    
    
    Outer Exception
      System.Net.Mail.SmtpException was unhandled
      Message="Failure sending mail."
      Source="System"
      StackTrace:
           at System.Net.Mail.SmtpClient.Send(MailMessage message)
           at LabDemos.Mailer.test() in C:\Users\username\Documents\Visual Studio 2008\Projects\LabDemos\LabDemos\Mailer.cs:line 40
           at LabDemos.Program.Main(String[] args) in C:\Users\username\Documents\Visual Studio 2008\Projects\LabDemos\LabDemos\Program.cs:line 48
           at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
           at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
           at System.Runtime.Hosting.ManifestRunner.Run(Boolean checkAptModel)
           at System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly()
           at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext, String[] activationCustomData)
           at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext)
           at System.Activator.CreateInstance(ActivationContext activationContext)
           at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone()
           at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
           at System.Threading.ThreadHelper.ThreadStart()
      InnerException: System.IO.IOException
           Message="Unable to read data from the transport connection: net_io_connectionclosed."
           Source="System"
           StackTrace:
                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)
           InnerException: