SmtpClient.Send随机导致SmtpException 4.7.0超时等待客户端输入

编程入门 行业动态 更新时间:2024-10-18 22:28:23
本文介绍了SmtpClient.Send随机导致SmtpException 4.7.0超时等待客户端输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我似乎找不到导致此问题的原因。

有时我会收到 SmtpException 4.7使用以下

如果您的计算机和交换服务器之间存在防火墙,则可能是防火墙问题。防火墙会阻止ip地址之间的端口,这与电子邮件的发送目的地无关。防火墙是我编程生活的祸根,所以绝对要问您的网络管理员服务器之间是否有防火墙,并请他检查防火墙是否正常工作。

就像是服务器上的NIC(网卡)坏了,甚至电缆也坏了。是的,您的网络管理员说网络坚如磐石……但永远不要相信网络管理员。 ;)

实际上,您的网卡,网络设置或以太网电缆也可能有问题。

您是否尝试过从其他计算机运行它?

I can't seem to find the cause for this problem.

Sometimes I get SmtpException "4.7.0 timeout waiting for client input" being thrown on using the following c# code for -4.0:

using System; using System.Net.Mail; namespace SendMail { class Program { static void Main(string[] args) { for (int i = 0; i < 100; i++) { string html = "<h1>TEST</h1>"; using (MailMessage mail = new MailMessage("sender@domain", "receiver@domain")) { mail.Subject = "Test"; mail.IsBodyHtml = true; mail.Body = html; using (SmtpClient client = new SmtpClient("<internal ip address>")) { client.UseDefaultCredentials = false; client.Credentials = new System.Net.NetworkCredential("<user name>", "<password>"); client.DeliveryMethod = SmtpDeliveryMethod.Network; client.Send(mail); } } } } } }

It usually crashes at the second attempt (i == 1).

I am aware I should create a single SmtpClient instance and reuse it in the loop but for the purpose of demonstration and in order to be as close as possible to the real code it has to be this way. While the above isn't quite like my production code it does suffer from the same random problem. I figured that if I could solve the problem with this code then I'd know what to do with my actual code, given that it really is a coding issue to begin with. I'm suspecting an obscure server configuration issue but I'm out of ideas on what it could possibly be.

Odd thing: despite being a timeout issue, the exception is thrown very quickly; there's no delay that would suggest an actual timing out problem.

The mail server is MS exchange-server-2007 running on windows-server-2008 SP2. There's no additional SMTP settings specified in app.config file.

I tried to put the code in a Do...While loop that tries five times to send the email back after putting the thread to sleep for one second. Unfortunately that doesn't help: when it fails, it will also fail at the very next attempts.

I also tried using Thread.Sleep(<delay>) before every calls to client.Send(message) but it made no appearant difference.

Our network admin is adamant on the network running without any issues (no packet drops caused by bad MTU setting or anything like that). He backs this up with the fact that there's only my code that seems to have problems (and he's right) and that it does not only happen on a segment of the network (also right).

It's unlikely that the firewall would be causing this either, as every mail my app sends is using internal addresses.

Anybody has a clue here? It would be much appreciated.

UPDATE:

I seem to be able to reproduce the problem every time when using default credentials instead:

using (SmtpClient client = new SmtpClient("<internal ip address>")) { client.UseDefaultCredentials = true; client.DeliveryMethod = SmtpDeliveryMethod.Network; client.Send(mail); }

UPDATE 2:

Nope. Not every time. Everything now works again (until next time).

I really can't put my finger on it.

UPDATE 3:

Interesting new development today: I attempted to create a new account inside MS Outlook with the same address I use with Exchange. Only this time instead of adding it as an MS Exchange address I tried setting it up as a POP3/SMTP account. Here is what happened upon testing the connection:

It's in french but look at the last line: it is the exact same error message I got with my code. This is a clear indication to me that the issue is not within my code.

Of course, this also means that this whole thread shouldn't be on SO. Still, I hope this extra test can help fellow developers out there who are struggling with a similar issue.

解决方案

This definitely sounds like a server or network issue. Reference this serverfault post for instance: serverfault/questions/344684/exchange-2007-email-error-451-4-7-0-timeout-waiting-for-client-input

It could be a firewall problem if there is a firewall between your machine and the exchange server. A firewall blocks ports between ip addresses, it doesn't matter where the email is going at all. Firewalls are the bane of my programming existence, so definitely ask your net admin if there is a firewall between the servers and have him check if it is working.

It could also be something like a bad NIC (network card) on the server or even a bad cable. Yes, your network admin said the network is rock solid... but never trust network admins. ;)

It could also be a problem with YOUR network card, network settings or ethernet cable, actually.

Have you tried running this from different computers?

更多推荐

SmtpClient.Send随机导致SmtpException 4.7.0超时等待客户端输入

本文发布于:2023-11-25 23:48:56,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1631831.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:客户端   Send   SmtpClient   SmtpException

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!