C# “无法从传输连接读取数据:net_io_connectionclosed。” - Windows Vista 商务版和 SMTP

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1143846/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 09:16:33  来源:igfitidea点击:

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

c#.netwindows-vistassissystem.net.mail

提问by johndacostaa

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

无法在 Windows Vista Business 中测试从 .NET 代码发送电子邮件。

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.

我正在编写代码,一旦它被证明,我将迁移到 SSIS 包。该代码是通过电子邮件向收件人列表发送错误消息。

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: 

回答by johndacostaa

I have found that the Vista Business OS does not come with IIS SMTP. I suspect this is the missing piece of the puzzle. Has anyone had any luck with this issue?

我发现 Vista Business OS 没有附带 IIS SMTP。我怀疑这是拼图的缺失部分。有没有人有幸解决这个问题?

回答by Simon_Weaver

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.

如果您在 SMTP 服务设置中指定了一个 IP 地址,那么请确保您在 IIS7 中指定了机器的 IP 地址,而不是将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

IIS7 可以轻松选择“本地主机”,但如果 IP 为 10.0.0.1,则会导致此错误

回答by Kamran Shahid

Is your code incompleted.Dash is correct in identifying it.Other then that check smtp component is installed or not check link text

您的代码是否不完整。Dash 识别它是正确的。然后检查 smtp 组件是否安装或不检查链接文本

回答by Joy

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.

Vista 和 Windows 7 没有任何 SMTP 服务器,此功能已从 Windows XP 中删除,因此您需要明确设置您的 SMTP 服务器,市场上有几种工具可用,您可以查看一下。此外,一旦您配置了 SMTP,请记住检查您将用于发送电子邮件的服务器名称。

回答by rus

upgrade to .NET 4.0 and apply all security updates

升级到 .NET 4.0 并应用所有安全更新

回答by Joe Fairchild

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.

有几种情况会导致此问题,以下是我发现的一些情况。问题:您提到“Exchange”——这是一个交换服务器吗?主机是否需要身份验证(也许您需要向客户端添加身份验证)?我首先会尝试做的是将主机分配给静态 IP 地址而不是主机名,以查看它是否首先起作用。如果是,则很可能是 DNS 映射有问题。

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)

如果您使用虚拟化运行交换服务器,则需要将 SmtpClient 配置为虚拟服务器的主机 IP,而不是物理托管服务器名称或 IP。右键单击默认 SMTP 虚拟服务器,选择属性,然后转到访问选项卡,单击中继,然后添加向 SMTP 服务器发送 SMTP 请求的计算机的 IP 地址。(ASP.net 站点)

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.

如果这不起作用,那是因为服务器阻止您发送 SMTP 数据包。您需要确保添加要从中发送 SMTP 消息到 SMTP 服务器的框。这是通过 IIS 的身份验证选项卡完成的。

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.

我还要指出,您应该处理邮件客户端,或者在“使用”语句中使用该客户端。这将确保“QUIT”被发送到服务器并正常关闭连接。

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

回答by JohnSM

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.

重新启动 IIS。我知道这听起来很傻,重新启动一切。(很抱歉碰到旧线程)。但有时重新启动 IIS 会很神奇。我遇到了完全相同的问题并重新启动解决了它。

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

可能是因为暂时无法解析名称“localhost”。我只是在这里发帖,以便现在面对它的人可能会在尝试进一步调查之前尝试这个快速修复。希望能帮助到你

回答by Sujit Senapati

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

如果您在 IIS 7 中使用 localhost(使用本地主机),则将其更改为机器的 IP 地址而不是 localhost 或 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]

信箱不可用。服务器响应为:5.7.1 无法中继 [email protected]

回答by Amol Shiledar

I am facing this issue last 6hr and I am new on that so I am trying to solve this issue in following way

我在过去 6 小时遇到了这个问题,我是新手,所以我试图通过以下方式解决这个问题

1) I opened command prompt (e.g. Ctrl + R type cmd and enter).
2) And check to SMTP server ping and check response.
3) If it's gets response then it's ok and to move next step 4 other wise smtp name is wrong.
4) Then I check by telnet smtp port (e.g. 25 ) is open or not.
5) Using this cmd we check the SMTP response.
6) telnet "yoursmtpname" "portno” (e.g. telnet smtp.gmail.com 25)
7) If telnet is not working, please install or add from control panel in add new features.
8) If it's working then it's pass result like.
9) 220 mx.google.com ESMTP .

1)我打开命令提示符(例如 Ctrl + R 键入 cmd 并输入)。
2) 并检查 SMTP 服务器 ping 并检查响应。
3)如果它得到响应,那么就可以了,移动下一步 4 其他明智的 smtp 名称是错误的。
4) 然后我通过 telnet smtp 端口(例如 25 )检查是否打开。
5) 使用此 cmd 我们检查 SMTP 响应。
6) telnet "yoursmtpname" "portno"(例如 telnet smtp.gmail.com 25)
7) 如果 telnet 不工作,请从控制面板安装或添加新功能
。8) 如果它工作正常,那么它的通过结果如下。
9) 220 mx.google.com ESMTP 。

Using above steps we can find out smtp connection is ready or not to sending mail.

使用上面的步骤我们可以找出smtp连接是否准备好发送邮件。

回答by Amir Chatrbahr

I had the same issue since I had multiple IP on my server (Virtual Servers) and my host was pointing to localhostwhile my SMTP Virtual Server was assigned to one particular IP:

我遇到了同样的问题,因为我的服务器(虚拟服务器)上有多个 IP,而我的主机指向localhost而我的 SMTP 虚拟服务器被分配给一个特定的 IP:

 <smtp deliveryMethod="Network">
       <network host="localhost" port="25" defaultCredentials="false"/>
 </smtp>

There are 2 solutions for this:

有两种解决方案:

  1. Change your code and set host to the particular IP that is being used by SMTP Virtual Server instead of localhost.
  2. Change SMTP Virtual Server IP to All Unassigned
  1. 更改您的代码并将主机设置为 SMTP 虚拟服务器正在使用的特定 IP,而不是 localhost。
  2. 将 SMTP 虚拟服务器 IP 更改为所有未分配

To see/change SMTP Virtual Server IP: Right click on Default SMTP virtual server, select Properties, on General tab change/see IP address.

要查看/更改 SMTP 虚拟服务器 IP:右键单击默认 SMTP 虚拟服务器,选择属性,在常规选项卡上更改/查看 IP 地址。

Hope this saves someone's day with the same issue.

希望这可以为遇到同样问题的人节省一天。