通过交流广东话电子邮件:现有连接被远程主机强行关闭广东话、电子邮件、主机

2023-09-04 00:58:53 作者:要走的人绝不挽留

我刚刚注意到,一些在我的code的电子邮件操作已失败,我试图修复它,但我不断收到以下错误:

I just noticed that some of the email operations in my code have been failing and am trying to fix it up, however I keep getting the following error:

System.Net.Mail.SmtpException: Failure sending mail. ---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
 ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
   at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
   at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
   --- End of inner exception stack trace ---
   at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
   at System.Net.DelegatedStream.Read(Byte[] buffer, Int32 offset, Int32 count)
   at System.Net.BufferedReadStream.Read(Byte[] buffer, Int32 offset, Int32 count)
   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)
   --- End of inner exception stack trace ---
   at System.Net.Mail.SmtpClient.Send(MailMessage message)

我的code是相当简单:

My code is fairly straightforward:

MailMessage mail = new MailMessage();
mail.To.Add(email_to);
mail.From = new MailAddress(email_from);
mail.Subject = email_subject;
mail.Body = email_body;


var client = new SmtpClient(smtp_server_url);
client.Credentials = new NetworkCredential(username, password, domain);
client.Timeout = 30000;
client.Send(mail);

没有人有任何想法可能是怎么回事?我们的Exchange服务器管理员说,她无法在日志中看到什么。

Does anyone have any ideas what could be going on? Our exchange server administrator says she can't see anything in the log.

此外,不认为这是一个惊喜,但是当我尝试从PowerShell中发送消息的同样的事情发生。

Also, not that this is a surprise, but the same thing happens when I try to send a message from powershell.

推荐答案

明白了!

从本质上看来,这个错误(错误code 10054)当您连接到服务器成功,但随后要求它做一些事情,它不具备做的发生。

Essentially it seems that this error (ErrorCode 10054) happens when you connect to a server successfully but then ask it to do something that it is not equipped to do.

在我这里的情况是发生了什么:

In my case here is what happened:

在我以前通过我们前面对邮件服务器mail.mycompany.com发送邮件 这不是Exchange服务器,虽然地址,这是您将浏览器来访问Outlook网络地址。 在此工作的罚款previously因为该地址非Web请求路由到Exchange服务器。在某些时候,这项政策改变了 - 在我们的例子,因为垃圾邮件管理被移交给AT& T公司。当然,我没有被告知任何这一点。 由于当时确实是在该网站上运行的服务器,将让我连接到它,但随后立即断开连接(或者甚至可能不允许它打开所有的方式) 设置正确的主机名解决了这一问题。