“无法从传输连接读取数据:net_io_connectionclosures。” - Windows Vista 商业版和 SMTP

发布于 2024-07-26 20:09:57 字数 4412 浏览 7 评论 0原文

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

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

代码如下,但是当我执行代码时出现异常。

我创建了一个简单的类来进行邮件发送...设计可以更好,我正在测试功能,然后再实现更强大的功能、方法等。

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);            
    }
}

异常消息

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: 

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: 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(12

梦幻之岛 2024-08-02 20:09:58

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

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

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

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

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

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)
}
世态炎凉 2024-08-02 20:09:58

重新启动 IIS。 我知道重新启动一切听起来很愚蠢。 (很抱歉撞到了旧线程)。 但有时重新启动 IIS 会产生神奇效果。 我遇到了完全相同的问题并重新启动解决了它。

可能是由于暂时无法解析名称“localhost”而发生的。 我只是在这里发帖,以便现在遇到此问题的人可能会在尝试进一步调查之前尝试此快速修复。 希望能帮助到你

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

痴情 2024-08-02 20:09:58

如果您已在 SMTP 服务设置中指定了 IP 地址,请确保在 IIS7 中指定计算机的 IP 地址,而不是输入 localhost

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

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

匿名。 2024-08-02 20:09:58

如果您在 IIS 7 中使用 localhost(使用本地主机),请将其更改为计算机的 IP 地址,而不是 localhost 或 127.0.0.1

另请按照以下链接相应更新您的邮件服务器中继:

邮箱不可用。 服务器响应为:5.7.1 无法中继[电子邮件受保护]

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]

山人契 2024-08-02 20:09:58

Vista和Windows 7没有任何SMTP服务器,这个功能从Windows XP开始就被删除了,所以你需要明确地设置你的SMTP服务器,市场上有几个工具可以实现这一点,你可以检查一下。
此外,配置 SMTP 后,请记住检查将用于发送电子邮件的服务器名称。

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.

哀由 2024-08-02 20:09:58

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

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

有 2 种解决方案为此:

  1. 更改代码并将主机设置为 SMTP 虚拟服务器正在使用的特定 IP,而不是 localhost。
  2. 将 SMTP 虚拟服务器 IP 更改为全部未分配

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

希望这可以帮助遇到同样问题的人。

I had the same issue since I had multiple IP on my server (Virtual Servers) and my host was pointing to localhost while my SMTP Virtual Server was assigned to one particular 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

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

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

书信已泛黄 2024-08-02 20:09:58

我使用 .NET Framework v4.5 在 VB 中开发了一个 Windows 服务应用程序,最近遇到了这个问题。

首先,介绍一点背景知识 - 在尝试处理错误“服务不可用,正在关闭传输通道。服务器响应是:错误:一个会话中消息太多”后,我遇到了 OP 的错误,该错误通过调用 Dispose 方法解决了每发送一封电子邮件后,在 SmtpClient 对象上。 为了超级安全,我还在 MailMessage 对象上调用了 Dispose。

好的,现在“一个会话中消息太多”问题已解决,但现在我偶尔会收到“无法从传输连接读取数据:net_io_connectionclose”错误。 惊人的。 事实证明,我没有一致地实现我的电子邮件类 - 在一个例子中,它被处理掉了,而在另一种情况下则没有。

下面是一个为我解决这两个问题的示例(它是用 VB 编写的,但你明白了):

With New clsEmail(True)
    With .Message
        .To.Add("[email protected]")
        .Subject = msgSubject
        .Body = msgContents
    End With

    .Server.Send(.Message)
    .Server.Dispose()
    .Message.Dispose()
End With

我的电子邮件类除其他外有 2 个属性 - 消息 (System.Net.Mail.MailMessage) 和服务器 (System.Net) .Mail.SmtpClient),这就是本示例中要处理的内容。

一旦我的服务中发送电子邮件的每个实例都以这种方式实现,我在发送数百封电子邮件后就没有遇到任何问题。

I developed a Windows Service application in VB using .NET Framework v4.5 and recently ran into this issue.

First, a little background - I ran into the OP's error after trying to deal with the error "Service not available, closing transmission channel. The server response was: Error: too many messages in one session" which was resolved by calling the Dispose method on the SmtpClient object after each email sent. Just to be ultra safe, I also called Dispose on the MailMessage object.

Okay, so now the 'too many messages in one session' issue is resolved but now I occasionally got the 'Unable to read data from the transport connection: net_io_connectionclosed' error. Awesome. Turns out I had not implemented my email class consistently - in one instance, it was being disposed of while in the other it was not.

Here's an example of what resolved both issues for me (it's in VB but you get the idea):

With New clsEmail(True)
    With .Message
        .To.Add("[email protected]")
        .Subject = msgSubject
        .Body = msgContents
    End With

    .Server.Send(.Message)
    .Server.Dispose()
    .Message.Dispose()
End With

My email class has, among other things, has 2 properties - Message (System.Net.Mail.MailMessage) and Server (System.Net.Mail.SmtpClient) which is what's being disposed in this example.

I haven't had a single problem after hundreds of emails once every single instance that sends email in my service was implemented in this way.

一个人的旅程 2024-08-02 20:09:58

我发现 Vista Business 操作系统没有附带 IIS SMTP。 我怀疑这就是拼图中缺失的一块。 有人在这个问题上有运气吗?

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?

以歌曲疗慰 2024-08-02 20:09:58

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

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

尾戒 2024-08-02 20:09:58

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

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

通过以上步骤我们可以了解 smtp 连接是否准备好发送邮件。

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

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 .

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

橘亓 2024-08-02 20:09:58

我一个月来也面临着同样的问题。 我尝试了微软官方网站上提供的所有可能的解决方案。 最后,我找到了它的根本原因。
我已在 web.config 文件中将 targetFramework 从 4.5.2 更新到 4.6.1

编译 debug="true" targetFramework="4.6.1"
httpRuntime maxRequestLength =“183500800”executionTimeout =“3600”targetFramework =“4.6.1”enableVersionHeader =“false”

上述解决方案对我有用,现在我的电子邮件已从应用程序成功触发。

I was facing the same issue for one month. I tried all the possible solutions provided on Microsoft's official site. Finally, I found the root cause of it.
I have updated targetFramework from 4.5.2 to 4.6.1 in web.config file.

compilation debug="true" targetFramework="4.6.1"
httpRuntime maxRequestLength="183500800" executionTimeout="3600" targetFramework="4.6.1" enableVersionHeader="false"

the above solution worked for me, and now my emails are triggering successfully from the application.

蹲在坟头点根烟 2024-08-02 20:09:58

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

upgrade to .NET 4.0 and apply all security updates

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文