我刚刚注意到我的代码中的某些电子邮件操作失败了并且我正在尝试修复它,但是我一直收到以下错误:
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)
我的代码相当简单:
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服务器管理员说她在日志中看不到任何内容。
此外,这不是一个惊喜,但当我尝试从powershell发送消息时也会发生同样的事情。
答案 0 :(得分:3)
知道了!
基本上似乎这个错误(ErrorCode 10054)发生在你成功连接到服务器但后来要求它做一些它没有配备的东西时。
就我而言,这里发生了什么:
答案 1 :(得分:1)
通常当我看到它是Exchange服务器上的配置时。在我们的环境中,我们的网络管理员必须明确允许计算机将Exchange服务器用作中继。如果运行我的代码的机器未明确添加到服务器,我收到此消息。希望这会有所帮助。