GVKun编程网logo

SmtpException:无法从传输连接中读取数据:net_io_connectionclosed(无法从传输连接中读取数据由于连接方)

10

最近很多小伙伴都在问SmtpException:无法从传输连接中读取数据:net_io_connectionclosed和无法从传输连接中读取数据由于连接方这两个问题,那么本篇文章就来给大家详细解答一

最近很多小伙伴都在问SmtpException:无法从传输连接中读取数据:net_io_connectionclosed无法从传输连接中读取数据由于连接方这两个问题,那么本篇文章就来给大家详细解答一下,同时本文还将给你拓展.conn.ManagedClientConnectionImpl@604ed9f0 java.net.ConnectException: Connection refused: connect、.jdbc4.MySQLNonTransientConnectionException: No operations allowed after connection closed.、Azure Cosmos DB - 间歇性 MongoConnectionException / IOException / SocketException、c# – Gmail:无法从传输连接中读取数据:net_io_connectionclosed等相关知识,下面开始了哦!

本文目录一览:

SmtpException:无法从传输连接中读取数据:net_io_connectionclosed(无法从传输连接中读取数据由于连接方)

SmtpException:无法从传输连接中读取数据:net_io_connectionclosed(无法从传输连接中读取数据由于连接方)

我正在使用SmtpClient图书馆通过以下方式发送电子邮件:

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

该代码在测试环境中可以正常工作,但是当我使用生产SMTP服务器时,该代码将失败,并显示SmtpException“发送邮件失败”。内部带有IOException“无法从传输连接读取数据:net_io_connectionclosed”。

我已经确认防火墙不是问题。客户端和服务器之间的端口打开得很好。我不确定还有什么可能引发此错误。

答案1

小编典典

编辑:超级Redux版本

请尝试使用端口587而不是465。在技术上,不建议使用端口465。


一堆包嗅探后,我想通了。首先,这是一个简短的答案:

.NET SmtpClient
支持通过STARTTLS进行加密。如果EnableSsl设置了该标志,则服务器必须使用STARTTLS响应EHLO,否则它将引发异常。有关更多详细信息,请参见MSDN文档。

其次,面向那些在将来遇到此问题的人提供了一个简短的SMTP历史课程:

过去,当服务还希望提供加密时,会为其分配一个不同的端口号,并在该端口号上立即启动SSL连接。随着时间的流逝,他们意识到为一个服务浪费两个端口号是很愚蠢的,他们设计了一种服务方式,允许使用STARTTLS在同一端口上进行纯文本和加密。通信将开始使用纯文本,然后使用STARTTLS命令升级到加密连接。STARTTLS成为SMTP加密的标准。不幸的是,由于在实施新标准时总是会发生这种情况,因此与那里的所有客户端和服务器都存在兼容性的大杂烩。

就我而言,我的用户试图将软件连接到强制进行即时SSL连接的服务器,这是Microsoft在.NET中不支持的旧方法。

.conn.ManagedClientConnectionImpl@604ed9f0 java.net.ConnectException: Connection refused: connect

.conn.ManagedClientConnectionImpl@604ed9f0 java.net.ConnectException: Connection refused: connect

DEBUG 2016-11-07 14:32:47,518  Get connection for route {}->http://127.0.0.1:8087->http://rdsearch.zhaopin.com:80
DEBUG 2016-11-07 14:32:47,519  Connecting to 127.0.0.1:8087
DEBUG 2016-11-07 14:32:48,530  Connection org.apache.http.impl.conn.DefaultClientConnection@91161c7 closed
DEBUG 2016-11-07 14:32:48,531  Connection org.apache.http.impl.conn.DefaultClientConnection@91161c7 shut down
DEBUG 2016-11-07 14:32:48,532  Releasing connection org.apache.http.impl.conn.ManagedClientConnectionImpl@604ed9f0
java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:117)
at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:177)
at org.apache.http.impl.conn.ManagedClientConnectionImpl.open(ManagedClientConnectionImpl.java:304)
at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:611)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:446)
at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:882)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:107)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:55)

.jdbc4.MySQLNonTransientConnectionException: No operations allowed after connection closed.

.jdbc4.MySQLNonTransientConnectionException: No operations allowed after connection closed.

com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operations allowed after connection closed.
    at sun.reflect.GeneratedConstructorAccessor65.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
    at com.mysql.jdbc.Util.getInstance(Util.java:386)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1015)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:989)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:975)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:920)
    at com.mysql.jdbc.ConnectionImpl.throwConnectionClosedException(ConnectionImpl.java:1311)
    at com.mysql.jdbc.ConnectionImpl.checkClosed(ConnectionImpl.java:1303)
    at com.mysql.jdbc.ConnectionImpl.createStatement(ConnectionImpl.java:2683)
    at com.mysql.jdbc.ConnectionImpl.createStatement(ConnectionImpl.java:2665)
    at security.view.util.SqlUtils.insert(SqlUtils.java:315)
    at security.view.util.SqlUtils.processKill(SqlUtils.java:109)
    at security.view.util.SqlUtils.sql(SqlUtils.java:148)
    at security.view.util.SqlUtils.sqlJsonObj(SqlUtils.java:418)
    at security.view.util.SqlUtils.processKill(SqlUtils.java:97)
    at security.view.util.SqlUtils.sql(SqlUtils.java:148)
 

Azure Cosmos DB - 间歇性 MongoConnectionException / IOException / SocketException

Azure Cosmos DB - 间歇性 MongoConnectionException / IOException / SocketException

如何解决Azure Cosmos DB - 间歇性 MongoConnectionException / IOException / SocketException?

我将 Azure Cosmos DB 4.0 与 MongoDB C# 驱动程序 2.10.4 结合使用。

大多数时候查询工作正常,但我遇到了这样的间歇性错误:

MongoDB.Driver.MongoConnectionException:向服务器发送消息时发生异常。 System.IO.IOException:无法将数据写入传输连接:远程主机强行关闭了现有连接。 System.Net.sockets.socketException: 一个现有的连接被远程主机强行关闭 在 System.Net.sockets.socket.BeginSend(... 在 System.Net.sockets.NetworkStream.BeginWrite --- 内部异常堆栈跟踪结束 --- 在 System.Net.sockets.NetworkStream.BeginWrite 在 System.Net.Security._SslStream.StartWriting 在 System.Net.Security._SslStream.ProcessWrite 在 System.Net.Security._SslStream.BeginWrite

发生该错误时,调用需要 10-25 秒才能失败。

我正在使用 @H_301_9@new MongoClient(MongoClientSettings.FromConnectionString(cnstr)) 构建 MongoClient,并且我使用的是带有这些参数 @H_301_9@?ssl=true&replicaset=globaldb&retrywrites=false 的连接字符串。

我尝试使用 @H_301_9@retryWrites=true(根据 Azure 支持建议),但这没有帮助。

我尝试了不同的设置,但都不起作用(@H_301_9@connect=direct、@H_301_9@maxIdleTimeMS=30000、@H_301_9@serverSelectionTimeout=5000ms、@H_301_9@socketTimeout=10000ms)。

导致这些异常的原因是什么?

解决方法

修复是设置/强制使用 TLS 1.2(基于 this Microsoft document):

//return new MongoClient(connectionString);
var settings = MongoClientSettings.FromConnectionString(connectionString);
settings.SslSettings = new SslSettings()
{
    EnabledSslProtocols = System.Security.Authentication.SslProtocols.Tls12
};
return new MongoClient(settings);

看起来虽然我的连接字符串有 ssl=true,但在某些服务器上还不够(错误是间歇性的)。 forcing TLS 1.2 通常可以修复相同的潜在错误,因此我认为在 Mongo 中它可能是相同的问题 - 它确实解决了问题。

c# – Gmail:无法从传输连接中读取数据:net_io_connectionclosed

c# – Gmail:无法从传输连接中读取数据:net_io_connectionclosed

我的应用程序运行了5年,没有任何问题.今天早上,我无法再使用特定的Gmail帐户发送电子邮件.我收到的例外是:无法从传输连接中读取数据:net_io_connectionclosed.使用其他帐户的凭据工作正常.帐户凭据未更改,我可以使用Gmail界面从帐户发送电子邮件.我联系了Google,他们的回复是该帐户看起来不错,它必须是您的应用程序…我的回复,应用程序没有更改并使用其他凭据工作.我的相关代码如下,有什么想法吗?
try
            {
                SmtpClient smtpClient = new SmtpClient();
                using (MailMessage message = new MailMessage())
                {
                    message.From = new MailAddress(Program.EMAIL_SENDER_ADDRESS,"SENDER NAME");
                    message.To.Add(new MailAddress(Program.ERROR_RECIPIENT));

                    message.Subject = callingClass + " ERROR: " + subject;

                    message.IsBodyHtml = true;

                    message.Body = body;

                    smtpClient.Host = "smtp.gmail.com";
                    smtpClient.Port = 587;
                    smtpClient.EnableSsl = true;
                    smtpClient.Credentials = new System.Net.NetworkCredential(Program.EMAIL_SENDER_ADDRESS,Program.EMAIL_SENDER_PASSWORD);

                    smtpClient.Send(message);
                    smtpClient.ServicePoint.CloseConnectionGroup(smtpClient.ServicePoint.ConnectionName);
                }
            }
            catch (Exception x)
            {
                //handle exception
            }

更新 – 在致电Google之后大约30分钟,它神奇地再次开始工作.我想应用程序自行修复了?!?!

解决方法

我不久前遇到过类似的问题.这最终成为解决方案,因为谷歌增加了他们的电子邮件应用程序安全性(截至2016年9月):

>在Gmail页面中,点击右上角帐户的头像图片.
>按“我的帐户”.
>按’登录&安全.’
>向下滚动到’Connected Apps&网站部分.
>将“允许不太安全的应用”切换为开启.

https://support.google.com/accounts/answer/6010255?hl=en

今天关于SmtpException:无法从传输连接中读取数据:net_io_connectionclosed无法从传输连接中读取数据由于连接方的分享就到这里,希望大家有所收获,若想了解更多关于.conn.ManagedClientConnectionImpl@604ed9f0 java.net.ConnectException: Connection refused: connect、.jdbc4.MySQLNonTransientConnectionException: No operations allowed after connection closed.、Azure Cosmos DB - 间歇性 MongoConnectionException / IOException / SocketException、c# – Gmail:无法从传输连接中读取数据:net_io_connectionclosed等相关知识,可以在本站进行查询。

本文标签: