c# - smtp 客户端 "failure sending mail"

标签 c# .net smtpclient

这是我的代码

for(int i = 0; i < number ; i++)
{
    MailAddress to = new MailAddress(iMail.to);
    MailAddress from = new MailAddress(iMail.from, iMail.displayName);
    string body = iMail.body;
    string subject = iMail.sub;
    oMail = new MailMessage(from, to);
    oMail.Subject = subject;
    oMail.Body = body;
    oMail.IsBodyHtml = true;
    oMail.Priority = MailPriority.Normal;
    oMail.Sender = from;
    s = new SmtpClient(smtpServer);
    if (s != null)
    {
        s.Send(oMail);
    }
    oMail.Dispose();
    s = null;
}

此循环发送超过 60,000 封电子邮件。但我的问题是,我在某些电子邮件中收到“发送邮件失败”,有时是 5000 封,有时则少于其余邮件的发送。我已经检查了所有这些错误的电子邮件是否有有效的电子邮件地址。不知道是什么问题。在这方面我真的需要帮助。

编辑:这是我的异常跟踪

Error - Failure sending mail.; Inner Ex - 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.CheckCommand.Send(SmtpConnection conn, String& response) at System.Net.Mail.MailCommand.Send(SmtpConnection conn, Byte[] command, String from) at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, SmtpFailedRecipientException& exception)

最佳答案

好吧,“发送电子邮件失败”应该有更多细节。但有几件事可能会导致这种情况。

  1. 对“发件人”地址的限制。如果您使用的地址不同,有些地址可能会被您的 SMTP 服务阻止,无法发送。
  2. 您的 SMTP 服务的防洪功能可能会阻止电子邮件外发。

无论是这些错误还是其他错误,您都需要查看异常和内部异常以获得更多详细信息。

关于c# - smtp 客户端 "failure sending mail",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2209617/

相关文章:

c# - .NET 6 源代码生成器和 C# 9 语法

c# - 在 C# Windows 应用程序中通过电子邮件发送附件

c# - 使用 RouteArea 后 ASP.NET MVC 5 路由停止工作

c# - 在 Global.asax 中给定值的变量有时会返回错误的值

c# - 获取一个类型的所有派生类型

c# - 使用主机作为 IP 地址的 SMTP 发送邮件时无法解析远程名称

c# - 如何向域对象的构造函数提供 RequestContext 数据?

.net - .NET 中 'using' 的用法

asp.net-mvc - 使用 smtp 发送电子邮件仅在通过 Outlook 发送后才有效

.net - Microsoft 停用 SmtpClient 的原因可能是什么?