通过c#中的循环发送电子邮件失败(使用.net smtp)

通过c#中的循环发送电子邮件失败(使用.net smtp),c#,.net,email,smtp,C#,.net,Email,Smtp,第一封电子邮件发送成功,其他电子邮件发送错误 堆栈跟踪- System.IO.IOException: Unable to read data from the transport connection: net_io_connectionclosed. at System.Net.Mail.SmtpReplyReaderFactory.ProcessRead(Byte[] buffer, Int32 offset, Int32 read, Boolean readLine)

第一封电子邮件发送成功,其他电子邮件发送错误

堆栈跟踪-

 System.IO.IOException: Unable to read data from the transport connection: net_io_connectionclosed.
       at System.Net.Mail.SmtpReplyReaderFactory.ProcessRead(Byte[] buffer, Int32 offset, Int32 read, Boolean readLine)
       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.SmtpClient.Send(MailMessage message)
请帮我解决这个问题

这是我的密码

SmtpClient SmtpServer = new SmtpClient(System.Configuration.ConfigurationSettings.AppSettings["SMTP_server"]);
                                    //email port
                                    SmtpServer.Port = Convert.ToInt32(System.Configuration.ConfigurationSettings.AppSettings["SMTP_Port"]);
                                    //mail server credentials
                                    var userName = System.Configuration.ConfigurationSettings.AppSettings["NetworkCredential_userName"];
                                    var password = System.Configuration.ConfigurationSettings.AppSettings["NetworkCredential_Password"];
                                    if (userName.Length == 0 && password.Length == 0)
                                    {
                                        SmtpServer.Credentials = new System.Net.NetworkCredential();
                                    }
                                    else
                                    {
                                        SmtpServer.Credentials = new System.Net.NetworkCredential(userName, password);
                                    }
                                    //ssl availablility
                                    SmtpServer.EnableSsl = Convert.ToBoolean(System.Configuration.ConfigurationSettings.AppSettings["EnableSsl"]);
                                    mail.Priority = MailPriority.High;
                                    SmtpServer.Send(mail);
                                    //disposing attachment after sending
                                    attachment.Dispose();
                                    SmtpServer.Dispose();

请尝试以下内容,但仅限fr本地机器,不应适用于生产环境-

在主机文件中,将127.0.0.1指向您的计算机名并

编码-

var client = new SmtpClient("local machine name")
client.Send(mail)

这是因为远程SMTP服务器防火墙规则。服务器规则突然更改,影响我的代码。实际上,我所做的是增加了线程的睡眠时间,线程开始正常工作

看起来你的连接已关闭。。。有密码吗?我只看到你发了一封邮件。这是完整的密码吗?该错误是否在您处理SMTPServer后发生?顺便问一下,如果你有一封以上的电子邮件要发送,你为什么要处理它呢。。我正在定义邮件并将其简单地传递到smtp服务器。只是想知道您是否已经看到了以下内容:?这对我没有帮助。直到今天,这项工作都很好。这是在生产环境中:(有时它取决于internet连接,考虑到这取决于生产环境,internet连接不会是专用连接!!我建议检查SMTP服务器是否可以通过给定端口访问!!尝试添加以下设置-Client.ServicePoint.MaxIdl。)时间=2;