第一封邮件发送成功,其他邮件发送错误。
堆栈跟踪 -
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();
最佳答案
这是由于远程 SMTP 服务器防火墙规则引起的。服务器规则突然更改,它影响了我的代码。实际上我所做的是我的线程的 sleep 时间增加并且它开始正常工作。
关于c# - 通过 C# 中的循环发送电子邮件失败(使用 .net smtp),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28984774/