SmtpException:无法读取从传输连接数据:net_io_connectionclosed [英] SmtpException: Unable to read data from the transport connection: net_io_connectionclosed

查看:10042
本文介绍了SmtpException:无法读取从传输连接数据:net_io_connectionclosed的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 SmtpClient 库使用以下可以发送电子邮件:

I am using the SmtpClient library to send emails using the following:

SmtpClient client = new SmtpClient();
client.Host = "hostname";
client.Port = 465;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.EnableSsl = true;
client.Credentials = new NetworkCredential("User", "Pass);
client.Send("from@hostname", "to@hostname", "Subject", "Body");

在code在我的测试环境中正常工作,但是当我使用生产的SMTP服务器时,code不能与 SmtpException 发送邮件失败。 与内 IOException异常无法从传输连接读取数据:net_io_connectionclosed

The code works fine in my test environment, but when I use production SMTP servers, the code fails with an SmtpException "Failure sending mail." with an inner IOException "Unable to read data from the transport connection: net_io_connectionclosed".

我已经确认防火墙是不是一个问题。端口打开客户端和服务器之间就好了。我不知道还有什么可以抛出这个错误。

I've confirmed that firewalls are not an issue. The port opens just fine between the client and the server. I'm not sure what else could throw this error.

推荐答案

编辑:超级终极版版本

尝试端口587,而不是465端口465在技术上是德precated。

Try port 587 instead of 465. Port 465 is technically deprecated.

一串数据包嗅探后,我想通了。首先,这里的答案很简单:

After a bunch of packet sniffing I figured it out. First, here's the short answer:

在.NET SmtpClient 支持通过STARTTLS加密。如果 EnableSsl 标志设置,服务器必须以EHLO用STARTTLS响应,否则会抛出异常。请参阅<一个href=\"http://msdn.microsoft.com/en-us/library/system.net.mail.smtpclient.enablessl%28v=vs.110%29.aspx\">MSDN文档了解更多信息。

The .NET SmtpClient only supports encryption via STARTTLS. If the EnableSsl flag is set, the server must respond to EHLO with a STARTTLS, otherwise it will throw an exception. See the MSDN documentation for more details.

其次,对于那些谁在未来在这个问题绊倒快速SMTP历史课:

Second, a quick SMTP history lesson for those who stumble upon this problem in the future:

早在一天,当服务想也提供他们被分配不同的端口号加密,并在该端口号,他们立即启动SSL连接。随着时间的推移,他们意识到这是愚蠢的浪费两个端口号为一个服务和他们设计的服务,让使用STARTTLS在同一端口上的明文和加密的方法。通讯将开始使用明文,然后使用STARTTLS命令升级到加密连接。 STARTTLS成为SMTP的加密标准。不幸的是,当一个新的标准实施,因为它总是会发生的,有兼容性与所有的客户端和服务器在那里。

Back in the day, when services wanted to also offer encryption they were assigned a different port number, and on that port number they immediately initiated an SSL connection. As time went on they realized it was silly to waste two port numbers for one service and they devised a way for services to allow plaintext and encryption on the same port using STARTTLS. Communication would start using plaintext, then use the STARTTLS command to upgrade to an encrypted connection. STARTTLS became the standard for SMTP encryption. Unfortunately, as it always happens when a new standard is implemented, there is a hodgepodge of compatibility with all the clients and servers out there.

在我的情况,我的用户试图软件连接到被强迫立即SSL连接,这是不是由微软在.NET支持的传统方法的服务器。

In my case, my user was trying to connect the software to a server that was forcing an immediate SSL connection, which is the legacy method that is not supported by Microsoft in .NET.

这篇关于SmtpException:无法读取从传输连接数据:net_io_connectionclosed的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆