c# - 通过 C# 中的循环发送电子邮件失败(使用 .net 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)
       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/

相关文章:

c# - 将 LINQ 的 Zip 与不返回值的闭包一起使用

ruby - 使用 Pony Mail 和 Sinatra 时连接被拒绝

html - 强制 Thunderbird 中的 html 电子邮件在容器中 float 元素

c# - SQLite 标量函数返回类型始终为字符串?

c# - 如何在文本框(WPF)中按 Control+Right 选择 2 个单词?

c# - 无法在 C# 项目中重新加载 C++ dll

c# - 委托(delegate)签名/通用委托(delegate)?

php - 无法与主机 smtp.gmail.com 建立连接网络无法访问 Laravel 电子邮件中的 #101 错误

c# - 上传到 Azure 存储的文件已损坏

c# - .Net 与网站管理员工具(Google.Apis.Webmasters.v3 Nuget 包)斗争