从ASP.NET网站发送电子邮件时如何解决随机错误

时间:2019-03-18 12:08:42

标签: c# .net sockets email smtp

我从ASP.NET(4.0)网站发送电子邮件:

SmtpClient mySMTPClient = new SmtpClient();
mySMTPClient.UseDefaultCredentials = false;
mySMTPClient.Host = "email.privateemail.com";
mySMTPClient.Port = 465; //I also tried 587 and none of them
mySMTPClient.Credentials = new System.Net.NetworkCredential("contact@xxxxxx.com", "xxxxxxxxxx");
mySMTPClient.EnableSsl = true;
mySMTPClient.DeliveryMethod = SmtpDeliveryMethod.Network;
mySMTPClient.Send(email);

我每天发送十几封电子邮件,而不是批量或循环发送。仅发送了大约一半。另一个因错误而失败:

ERROR MESSAGE: Failure sending mail.
INNER EXCEPTION: 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(ServicePoint servicePoint)
   at System.Net.Mail.SmtpTransport.GetConnection(ServicePoint servicePoint)
   at System.Net.Mail.SmtpClient.GetConnection()
   at System.Net.Mail.SmtpClient.Send(MailMessage message)

失败的电子邮件是随机的。我没有模式。

Windows Server 2008 SP2内部版本6002 防火墙PfSense-工程师说规则配置正确,否则所有电子邮件都会失败。 第三部分电子邮件提供商:他们说一切都已正确配置,并且无论如何也无法进行任何修改。

我不是网络工程师,也没有网络工程师。我的问题是,我该怎么做才能找到根本原因,以便可以解决?

现在我尝试使用Process Monitor,但是它对我没有帮助(或者我不知道外观如何。)

我找到了几篇有关此问题的文章,由于它们的解决方案不适用于我的情况,因此目前为止没有任何帮助(我尝试过一些没有成功的事情)。

谢谢

1 个答案:

答案 0 :(得分:0)

这是NameCheap的问题,我已经厌倦了他们的电子邮件服务,他们无法修复它,我的代码在Gmail和Hotmail上运行正常,但是在使用NameCheap的SMTP服务器(“从传输连接读取数据:远程主机强行关闭了现有连接。”