这是我的代码
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)
最佳答案
好吧,“发送电子邮件失败”应该有更多细节。但有几件事可能会导致这种情况。
- 对“发件人”地址的限制。如果您使用的地址不同,有些地址可能会被您的 SMTP 服务阻止,无法发送。
- 您的 SMTP 服务的防洪功能可能会阻止电子邮件外发。
无论是这些错误还是其他错误,您都需要查看异常和内部异常以获得更多详细信息。
关于c# - smtp 客户端 "failure sending mail",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2209617/